帮我找到此输入中的错误 [英] Help me find the errors in this input
本文介绍了帮我找到此输入中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include < stdio.h >
#include < conio.h >
int main()
{
int i;
float num,average,sum;
printf( 最大输入数量:);
scanf( %d,& i);
for (i = 1 ; i> = 1 ; ++ i)
{
printf( 输入%d \ n:,i);
scanf( %d,& i);
sum = + num;
}
jump:
average = sum /(i- 1 );
printf( 平均值:%。2f,i);
getch();
return 0 ;
}
我的尝试:
我不认为我得到的输出是正确的
解决方案
你使用scanf
有两个错误。首先,您使用浮点格式类型来读取整数。其次,您需要提供变量的地址,而不是其值。因此,将其更改为:
int i; // 此处没有任何意义
float num,average,sum;
printf( 最大输入数量:);
scanf( %d,& i);
你在其他地方重复一遍(很容易看到)。您还尝试在使用i
作为其循环计数器的循环中将更多值读入变量i
。 / BLOCKQUOTE>
#include<stdio.h> #include<conio.h> int main() { int i; float num, average, sum; printf("Maximum num of inputs: "); scanf("%d",&i); for(i=1;i>=1;++i) { printf("Enter %d\n: ",i); scanf("%d",&i); sum=+num; } jump: average=sum/(i-1); printf("Average: %.2f",i); getch (); return 0; }
What I have tried:
I don't think the output that I got is correct解决方案Your use ofscanf
is wrong on two counts. First you are useing a floating point format type to read an integer. Second you need to provide the address of the variable, not its value. So change it to:
int i; // no point in putting a value here float num, average, sum; printf("Maximum num of inputs: "); scanf("%d",&i);
You repeat this in other places (easy to see). You are also trying to read further values into variablei
within the loop that is usingi
as its loop counter.
这篇关于帮我找到此输入中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文