帮我找到此输入中的错误 [英] Help me find the errors in this input

查看:80
本文介绍了帮我找到此输入中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #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 of scanf 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 variable i within the loop that is using i as its loop counter.


这篇关于帮我找到此输入中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆