| 
                
                  | ety   
         
  
 | 分享:        ▲
                    
                      ▼         
 
   其实你的程式并没有错, 而是 while 出了问题! while 这个指令会判断你所给予的条件是否符合, 如果符合就会执行, 不符合则是跳开! 而当 a 等于 0 时, 这就是不合格的参数了! 所以你的程式能完整的执行完流程但却不能正常的结束! 只要把 while 的参数改为 a != 0, 让 while 这个指令来判断是否为 0, 而不要让 while 去判断 0 是否大于等于 1,  就可以解决这个问题了! 附上我的程式码, 供你参考:复制程式 
#include <stdio.h>
int sum( int a, int b )
{
       int c;
       c = 0;
       printf( "Please key in NO.%d integer: ", a );
       scanf( "%d", &c );
       b = b + c;
       printf( "\nNow sum is: %d\n\n", b );
       return( b );
}
void average( int a, int b )
{
       int c;
       if( a == 0 )
       { c = 0; }
       else
       { c = a / b; }
       printf( "The average value is: %d\n", c );
}
int main( void )
{
       int Loop;
       int Input;
       int Sum;
       int Number;
       int Average_Value;
       Loop = 0;
       Input = 0;
       Sum = 0;
       Number = 1;
       Average_Value = 0;
       printf( "\nHow many integers?" );
       scanf( "%d", &Loop );
       printf( "\n" );
       if( Loop <= 0 )
       { printf( "Average value is: %d\n", Average_Value ); }
       else
       {
              while( Loop != 0 )
              {
                     Sum = sum( Number, Sum );
                     Loop = Loop - 1;
                     Number = Number + 1;
              }
              average( Sum, Number );
       }
       printf( "\nExit!\n" );
       return( 0 );
}
 
 [ 此文章被ety在2005-08-19 13:36重新编辑 ] 
 |  
                  | 
                
                  | 
 |  
                  |  x1  [3 楼]
                    
                    
                     From:台湾和信超媒体
 |  Posted:2005-08-19 13:11 | |  |  
                
                  | youchun 
         
  
 | 分享:        ▲
                    
                      ▼         
 
   不是有 int d 来做 counter ? 至于 a 可以加个 int tmp 暂存 我在你原本程式更改处加上 //here ety 所提到的检查也请楼主注意 最后, 如果要计算到小数点下 请用 double 或 float复制程式 
#include<stdio.h>
int main()
{
     int a,b,c=0,d=1,tmp;
     
     printf("请问一共有几个数字:");
     scanf("%d",&a);
     tmp =a ; //here
     
     while(tmp>=1){//here
     
           
           printf("请输入第%d个数字:",d);
           scanf("%d",&b);
           
           c += b;
           
           printf("\n目前总和是%d\n\n",c);
           
           tmp--;//here
           d++;
           
     }
     printf("平均值为%d\n",c/a);
     
     return 0;
}
 |  
                  | 
                
                  | 
 |  
                  |  x1  [4 楼]
                    
                    
                     From:台湾中华电信
 |  Posted:2005-08-19 15:07 | |  |  
                
                  | 夷希微 
         
   
  
 | 分享:        ▲
                    
                      ▼         
 
   请问有规定一定要用 while 来做吗?这个问题用 for 来做比较好解决吧 ^^"    #include<stdio.h>int main()
 
 {
 int a,b,c=0,d=1;
 
 printf("请问一共有几个数字:");
 scanf("%d",&a);
 
 for(d=1;d<=a;d++){
 
 
 printf("请输入第%d个数字:",d);
 scanf("%d",&b);
 
 c += b;
 
 printf("\n目前总和是%d\n\n",c);
 }
 
 
 printf("平均值为%d\n",c/a);
 
 return 0;
 }
 如果结果要有小数的话,使用强制转型(作弊)的方式也可以达到效果唷 ^^"    #include<stdio.h>int main()
 
 {
 int a,b,c=0,d=1;
 
 printf("请问一共有几个数字:");
 scanf("%d",&a);
 
 for(d=1;d<=a;d++){
 
 
 printf("请输入第%d个数字:",d);
 scanf("%d",&b);
 
 c += b;
 
 printf("\n目前总和是%d\n\n",c);
 }
 
 
 printf("平均值为%.2f\n",(float)c/a);
 
 return 0;
 }
       
 |  
                  | 
                
                  | 
 |  
                  |  x1  [5 楼]
                    
                    
                     From:台湾中华电信 
 |  Posted:2005-08-21 18:49 | |  |  
                
                  | 珀琥 
         
  
 | 分享:        ▲         
 
   复制程式
#include<stdio.h>
main()
{
      int a,b=0,c=1,d=0,e=0;
      printf("请问有多少个数字:");
      scanf("%d",&a);
      d=a;
      if (a>0){
      do{
      printf("请输入第%d个数字:",c);
      a=a-1;
      c++;
      scanf("%d",&b);
      e +=b;
      }while(a>0);
      printf("平均值=%d\n",(e/d));
      }
      system("pause");
      }
 
 |  
                  | 
                
                  | 
 |  
                  |  x0  [6 楼]
                    
                    
                     From:香港特别行政区
 |  Posted:2005-08-22 18:17 | |  |  |