新手学C语言,简单的问题,求大神解答,谢谢啦

源代码:#include<stdio.h>doubledistance(x1,y1,x2,y2);intmain(void){doublex1,x2,y1,y2,d;pr... 源代码:
#include<stdio.h>

double distance(x1,y1,x2,y2);
int main(void)
{
double x1,x2,y1,y2,d;
printf("Input x1,y1:");
scanf("%.2f%.2f",&x1,&y1);
printf("Input x2,y2:");
scanf("%.2f%.2f",&x2,&y2);
d=dist(x1,y1,x2,y2);

printf("distance=%.2f",d);
return 0;
}
double distance(x1,y1,x2,y2)
#include <math.h>
{
double s;
s=sprt(pow(x1-x2,2)+pow(y1-y2,2));
return s;
}
问题好多啊。汗!

C:\Users\KTZ1009\Desktop\新建文件夹\2.cpp(3) : error C2065: 'x1' : undeclared identifier
C:\Users\KTZ1009\Desktop\新建文件夹\2.cpp(3) : error C2065: 'y1' : undeclared identifier
C:\Users\KTZ1009\Desktop\新建文件夹\2.cpp(3) : error C2065: 'x2' : undeclared identifier
C:\Users\KTZ1009\Desktop\新建文件夹\2.cpp(3) : error C2065: 'y2' : undeclared identifier
C:\Users\KTZ1009\Desktop\新建文件夹\2.cpp(3) : error C2078: too many initializers
C:\Users\KTZ1009\Desktop\新建文件夹\2.cpp(11) : error C2064: term does not evaluate to a function
c:\program files (x86)\microsoft visual studio\vc98\include\math.h(36) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
c:\program files (x86)\microsoft visual studio\vc98\include\math.h(36) : fatal error C1004: unexpected end of file found

2.obj - 1 error(s), 0 warning(s)
求大神解答一下错误吧 ,谢谢啦
展开
 我来答
dagewxw
2013-11-14 · TA获得超过5928个赞
知道大有可为答主
回答量:3523
采纳率:67%
帮助的人:960万
展开全部
#include<stdio.h>
#include <math.h>
double distance(double x1,double y1,double x2,double y2);
int main(void)
{
double x1,x2,y1,y2,d;
printf("Input x1,y1:");
scanf("%.2f%.2f",&x1,&y1);
printf("Input x2,y2:");
scanf("%.2f%.2f",&x2,&y2);
d=distance(x1,y1,x2,y2);

printf("distance=%.2f",d);
return 0;
}
double distance(double x1,double y1,double x2,double y2)
{
double s;
s=sqrt(pow(x1-x2,2)+pow(y1-y2,2));
return s;
}

头文件放在最开始,
distance函数调用错误写成了dist
sqrt也写错了,写成了sprt
函数声明要加类型
追问
那上面的四个变量未清楚定义是什么意思啊。求解。
哦,我明白了,谢谢。
追答
#include
#include
double distance(double x1,double y1,double x2,double y2);
int main(void)
{
double x1,x2,y1,y2,d;
printf("Input x1,y1:");
scanf("%.2f%",&x1);
getchar();
scanf("%.2f%",&y1);
getchar();
printf("Input x2,y2:");
scanf("%.2f",&x2);
getchar();
scanf("%.2f",&y2);
d=distance(x1,y1,x2,y2);

printf("distance=%.2f",d);
system("pause");
return 0;
}
double distance(double x1,double y1,double x2,double y2)
{
double s;
s=sqrt(pow(x1-x2,2)+pow(y1-y2,2));
return s;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式