第三章:顺序程序设计03
让编程改变世界
Change the world by program
题目:输入三角形的三边长,求三角形面积。 已知三角形的三边长a,b,c,则该三角形的面积公式为: [caption id="attachment_64" align="aligncenter" width="150"] C语言计算数学公式[/caption] 其中s = (a+b+c)/2 [codesyntax lang="c"]
#include <stdio.h> #include <math.h>void main() {float a,b,c,s,area;scanf(“%f,%f,%f”,&a,&b,&c);s=1.0/2*(a+b+c);area=sqrt(s*(s-a)*(s-b)*(s-c));printf(“a=%7.2f,b=%7.2f,c=%7.2f,s=%7.2fn”,a,b,c,s);printf(“area=%7.2fn”,area); }[/codesyntax] [caption id="attachment_65" align="aligncenter" width="150"] C语言解决数学问题[/caption] [codesyntax lang="c"]
#include <stdio.h> #include <math.h>void main() {double a, b, c, disc, x1, x2, p, q;scanf(“a=%f,b=%f,c=%f”, &a, &b, &c);disc = b*b - 4*a*c;p = -b / (2*a);q = sqrt(disc) / (2*a);x1 = p+q; x2 = p-q;printf(“nx1=%5.2fnx2=%5.2fn”, x1, x2); }[/codesyntax] [buy] 获得所有教学视频、课件、源代码等资源打包 [/buy] [Downlink href='http://kuai.xunlei.com/d/LMZIRLRTDDKK']视频下载[/Downlink]