C语言小程序7

来源:百度知道 编辑:UC知道 时间:2024/05/09 06:24:49
我的程序哪里不对? 为何对角线长的结果不对呢?(设x,y矩形边长,s,面积,M为周长,n为对角线长)
main()
{
float x,y,s,m,n;
printf("pls input x=,y=?");
scanf("%f,%f",&x,&y);
s=x*y;
m=2*x+2*y;
n=sqrt (x*x+y*y);
printf("s=%6.2f,m=%4.2f,n=%5.2f",s,m,n);
getch();
}
#include "conio.h" ---二楼的 ,这个是什么意思 什么时候用丫? 谢

以下是我改的,也没什么错。加了个头文件就运行正确了,就是scanf那行输入时要输“3,4”中间加个“,”:
#include "math.h"
#include "conio.h"
main()
{
float x,y,s,m,n;
printf("pls input x=,y=?");
scanf("%f,%f",&x,&y);
s=x*y;
m=2*x+2*y;
n=sqrt (x*x+y*y);
printf("s=%6.2f,m=%4.2f,n=%5.2f",s,m,n);
getch();
}

1.scanf("%f,%f",&x,&y); //这样写不太好可以改为scanf("%f%f",&x,&y);
2.n=sqrt (x*x+y*y);
改为n=sqrt ((double)(x*x+y*y));试试

用sqrt()要加上头文件 #include <math.h>
printf()和sacnf()加上 #include <stdio.h>

我拿去运行了的, 最后的结果是对的。
是不是你程序问题哟!