请各位大侠帮帮忙~为什么此程序无法执行~
来源:百度知道 编辑:UC知道 时间:2024/05/25 17:44:39
#include<stdio.h>
void main()
{
double n1,n2,total;
printf("This program adds two floating-point numbers.\n");
printf("1st number?");
n1=GetReal();
printf("2nd number?");
n2=GetReal();
total=n1+n2;
printf("The total is %g\n",total);
}
void main()
{
double n1,n2,total;
printf("This program adds two floating-point numbers.\n");
printf("1st number?");
n1=GetReal();
printf("2nd number?");
n2=GetReal();
total=n1+n2;
printf("The total is %g\n",total);
}
看看你的GetReal函数有没有问题。printf("The total is %g\n",total); --》printf("The total is %f\n",total);
#include<stdio.h>
void main()
{
float n1,n2,total;
printf("This program adds two floating-point numbers.\n");
printf("1st number?\n");
scanf("%f",&n1);
//n1=GetReal();
printf("2nd number?\n");
scanf("%f",&n2);
//n2=GetReal();
total=n1+n2;
printf("The total is %f\n",total);
}
在#include<stdio.h>后增加:
double GetReal()
{
double f;
scanf("%lf",&f);
return f;
}