list2.c

来源:互联网 发布:下载手机截图软件 编辑:程序博客网 时间:2024/05/24 06:05

/*list2.c
 *********************
 计算一系列整数的平均值,输入的结尾以-1 标示
 */
#include<stdio.h>

main()
{             
      int i=0;
      int value,total;
      float ave;
     
      printf("This program average a list of integers./n");
      printf("Signal end of the list with a -1./n");
      total=0;
      while(1){
               printf("?  ");
               scanf("%d",&value);
               if(value==-1) break;
               total+=value;
               i++;
               }
      ave=1.0*total/i;
      printf("The average is %g/n",ave);
     
      getch();
}

原创粉丝点击