苏小红版第四版C语言程序设计第五章习题
//5.1
#include<stdio.h>
int main(void)
{
int x;
printf("Please input x :");
scanf("%d", &x);
if (x < 0)x = -x;
else if (x >= 0)x = x;
printf("|x|=%d", x);
return 0;
}
//5.2
#include<stdio.h>
#include<math.h>
int main(void)
{
int x;
printf("Please input x:");
scanf("%d", &x);
if (x % 2 == 0)
{
printf("为偶数");
}
else if (x % 2 != 0)
{
printf("为奇数");
}
return 0;
}
//5.3
#include<stdio.h>
#include<math.h>
int main(void)
{
double a, b, c, area, s;
printf("请输入三角形的三边a,b,c:");
scanf("%lf %lf %lf", &a, &b, &c);
if ((a + b > c) && (a + c > b) && (b + c > a))
{
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("三角形的面积为:%lf\n", area);
}
else
{
printf("输入的a