C语言--计算数组的平均值


 1 //数组

2 int main() 3 { 4 int muber[100]; 5 double sum = 0.0; 6 int cnt =0; 7 int x; 8 scanf("%d", &x); 9 while( x != -1) 10 { 11 muber[cnt] = x; 12 cnt ++; 13 sum += x; 14 scanf("%d", &x); 15 } 16 if( cnt >0) 17 { 18 int i; 19 double average = sum / cnt; 20 printf("平均值是%lf\n", average); 21 for (i =0;i<cnt; i++) 22 { 23 if (muber[i] > average){ 24 printf("大于平均值的数为:%d ",muber[i]); 25 } 26 } 27 } 28   return0; 29 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM