c语言 scanf 用法 输入双精度,在c中使用scanf和循环输入多个双精度数据,并且没有数组循环...

我的程序假设读取多个输入并显示最小值,最大值,总和和平均值。它应该是这样的:在c中使用scanf和循环输入多个双精度数据,并且没有数组循环

输入:

2.5 5 3.5 4.5 jfkjk

输出:

min is 2.5

max is 5

sum is 15.5

average is 3.875

该方案被认为当它到达一个非数字或一个换行符退出。用户可以输入尽可能多的数字。我不能使用数组,并且必须使用循环。 这是我的计划是什么样子:

void numbers()

{

double digit;

double sum = 0;

double avg = 0;

double max;

double min;

unsigned count = 0;

//int c;

max = 0;

printf("Input:");

do {

scanf("%lf", &digit);

min = digit;

if(max < digit)

digit = max;

if(min < digit)

digit = min;

sum += digit;

count++;

avg = sum/count;

} while(scanf("%lf", &digit)==1)

printf(" min is %lf max is %lf sum is %lf avg is %lf count is %u", min, max, sum, avg, count);

}

打印出:

Input:2.2 2.3 5 3.5 blah

min is 3.500000 max is 0.000000 sum is 0.000000 avg is 0.000000 count is 4

+0

先用正确的输入检查你的程序,然后尝试further.see Liho答案,并使用一个scanf函数与环路和移动scanf函数内部循环来之前。 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值