关于while语句用法
#include <stdio.h>int main()
{
float num = 0;
double sum = 0;
int status;
do
{
printf("请输入合法的数字:");
do
{
sum = sum + num;
status = scanf("%f", &num);
} #include <stdio.h>
int main()
{
float num = 0;
double sum = 0;
int status;
do
{
printf("请输入合法的数字:");
do
{
sum = sum + num;
status = scanf("%f", &num);
} while (getchar() != '\n' && status == 1);
} while(status == 1);
printf("结果是:%.2lf\n", sum);
return 0;
}
printf("结果是:%.2lf\n", sum);
return 0;
}
求问大佬这个while (getchar() != '\n' && status == 1); while(status == 1)在语句的含义到底什么意思,在里面表达什么意思? scanf("%f", &num) 返回成功存入 的数量。这里只有1个,num,成功返回1
页:
[1]