#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define Pi 3.1415926
int main()
{
double r, h, S;
while (1)
{
printf("r=");
scanf_s("%f", &r);
printf("h=");
scanf_s("%f", &h);
if (r > 0 && h > 0)
{
S = Pi*r*(r + sqrt(r*r + h*h));
printf("面积为%.2f", S);
break;
}
else
{
printf("请重新输入!\n");
}
}
system("pause");
return 0;
}
double要用%lf,不是%f
你明明占8个字节,但你告诉程序只取4个字节,那取到个什么可想而知。