c 程序来计算三角形面积看下为什么运行的时候不正确?#include "stdio.h"#include "math.h"main(){ double a,b,c,s,area; printf("please input 3 numbers:\n"); scanf("%f,%f,%f",&a,&b,&c); if((a+b>c)&&(a+c>b)&&(b+c>a)) {
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/25 07:06:51
![c 程序来计算三角形面积看下为什么运行的时候不正确?#include](/uploads/image/z/7216265-65-5.jpg?t=c+%E7%A8%8B%E5%BA%8F%E6%9D%A5%E8%AE%A1%E7%AE%97%E4%B8%89%E8%A7%92%E5%BD%A2%E9%9D%A2%E7%A7%AF%E7%9C%8B%E4%B8%8B%E4%B8%BA%E4%BB%80%E4%B9%88%E8%BF%90%E8%A1%8C%E7%9A%84%E6%97%B6%E5%80%99%E4%B8%8D%E6%AD%A3%E7%A1%AE%3F%23include+%22stdio.h%22%23include+%22math.h%22main%28%29%7B++++double+a%2Cb%2Cc%2Cs%2Carea%3B++++printf%28%22please+input+3+numbers%3A%5Cn%22%29%3B++++scanf%28%22%25f%2C%25f%2C%25f%22%2C%26a%2C%26b%2C%26c%29%3B++++if%28%28a%2Bb%3Ec%29%26%26%28a%2Bc%3Eb%29%26%26%28b%2Bc%3Ea%29%29++++++%7B)
c 程序来计算三角形面积看下为什么运行的时候不正确?#include "stdio.h"#include "math.h"main(){ double a,b,c,s,area; printf("please input 3 numbers:\n"); scanf("%f,%f,%f",&a,&b,&c); if((a+b>c)&&(a+c>b)&&(b+c>a)) {
c 程序来计算三角形面积
看下为什么运行的时候不正确?
#include "stdio.h"
#include "math.h"
main()
{
double a,b,c,s,area;
printf("please input 3 numbers:\n");
scanf("%f,%f,%f",&a,&b,&c);
if((a+b>c)&&(a+c>b)&&(b+c>a))
{
printf("可以构造出三角形\n");
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("三角形的面积为:%d\n",area);
}
else
printf("不能构造出三角形\n");
}
c 程序来计算三角形面积看下为什么运行的时候不正确?#include "stdio.h"#include "math.h"main(){ double a,b,c,s,area; printf("please input 3 numbers:\n"); scanf("%f,%f,%f",&a,&b,&c); if((a+b>c)&&(a+c>b)&&(b+c>a)) {
1.首先可以肯定的是:scanf()可以输入double类型,格式化参数为%lf,即scanf("%lf,%lf,%lf",&a,&b,&c).在输入的时候,用逗号隔开.如果输入的时候仅用空格和回车,则scanf应该为scanf("%lf%lf%lf",&a,&b,&c);
2.当然,跟 printf() 不同,scanf() 用 %lf 代表双精度数,用 %f 代表浮点数.一般情况输入为什么型,输出也是,所以printf()中的%d改为%lf或者%f即可.
#include "stdio.h"
#include "math.h"
void main()
{
double a,b,c,s,area;
printf("please input 3 numbers:\n");
scanf("%lf,%lf,%lf",&a,&b,&c);//_____________1.
if((a+b>c)&&(a+c>b)&&(b+c>a))
{
printf("可以构造出三角形\n");
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("三角形的面积为:%lf\n",area);//______________2.
}
else
printf("不能构造出三角形\n");
}