|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <math.h>
int main()
{ int a,b,c,p,s;
a=3;
b=4;
c=5;
p=(1.0/2)*(a+b+c);
s=sqrt(p*(p-a)*(p-b)*(p-c));
printf("a=%d,b=&d,c=%d,p=%d,s=%d",a,b,c,p,s);
}
本帖最后由 yuweb 于 2019-10-30 09:00 编辑
1、p,s用double存储,除非你能保证p=(a+b+c)/2;始终是整除才用int
2、int main()添加return 0;防止警告
3、printf("a=%d,b=&d,c=%d,p=%d,s=%d \n",a,b,c,p,s);中b=&d错了,应该是b=%d
改成printf("a=%d,b=%d,c=%d,p=%lf,s=%lf \n",a,b,c,p,s);
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int a,b,c;
- double p,s;
- a=3;
- b=4;
- c=5;
-
-
- p=(a+b+c)/2;
-
- s=sqrt(p*(p-a)*(p-b)*(p-c));
-
- printf("a=%d,b=%d,c=%d,p=%lf,s=%lf \n",a,b,c,p,s);
-
- return 0;
- }
复制代码
|
|