新手学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)
求大神解答一下错误吧 ,谢谢啦 展开
#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)
求大神解答一下错误吧 ,谢谢啦 展开
1个回答
展开全部
#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 <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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询