小编use*_*127的帖子

C程序找平均值,代码有什么问题?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
double sum = 0;
int ii = 0;
char buf[256], *token;
printf("Enter the numbers to average on a single line, separated by space and press enter when done\n");
fgets(buf, 255, stdin);
token = strtok(buf, " ");
while (token != NULL)
{
    sum += atof(token);
    ii++;
    token = strtok("", " ");    // Get next number
}
printf("Average is %lf", sum / (double)ii);
return 0;
}
Run Code Online (Sandbox Code Playgroud)

上述程序是为了找到用户给出的大量数字.该程序没有错误.我有代码的这些问题:

当你运行它时,它会要求你输入nos.由您找到平均值的空格分隔.当您输入以空格分隔的数字时 - 例如您输入 - 9080 5749 4343 …

c average

2
推荐指数
1
解决办法
254
查看次数

标签 统计

average ×1

c ×1