1 #include <math.h>
2 #include <stdio.h>
3 int main()
4 {
5 float a,b,c,p,s;
6 scanf("%f,%f,%f",&a,&b,&c);
7 p=(a+b+c)/2.0;
8 s=sqrt(p*(p-a)*(p-b)*(p-c));
9 printf("the area of triangle is %.2f.\n",s) ;
2 #include <stdio.h>
3 int main()
4 {
5 float a,b,c,p,s;
6 scanf("%f,%f,%f",&a,&b,&c);
7 p=(a+b+c)/2.0;
8 s=sqrt(p*(p-a)*(p-b)*(p-c));
9 printf("the area of triangle is %.2f.\n",s) ;
10 }
如上:
1、若int a,b,c;float p,s;
当a=3,b=4,c=6时,运行结果s=0.00,
故表达式(如7行)中定义的变量的数据类型要一致;、
2、不可6、7两行颠倒,虽然编译后不会提示错误,但是运行结果不对。
颠倒时:没有a,b,c输入的值,7行的表达式是没有运算结果的,程序不会在没有跳转语句,输入a,b,c的值时,逆向再回去算7行的表达式,这就是“顺序”结构!
3、8行中*不可省略;
4、编译时,要链接math函数库,即:gcc -o s s.c -lm,s为程序名,m为math的缩略词。