求数组中元素的平均值。 #include "stdio.h" float aver(float a[ ],int n) { int i; float av,s=a[0]; for(i=1;i a av; (av) &sco[i] sco,5
举一反三
- 【单选题】以下程序求数组元素平均值,请于空白处填空。 #include "stdio.h" #define N 10 int main() { int x[N],i;float s=0; printf("Enter 10 integers: "); for(i=0;i<N;i++) { scanf("%d",&x[i]); —————— } printf("av=%f ",s/N); return 0; } A. s+=x[i]; B. s=s+x(i) C. s+=x[i] D. s=s+x[i]
- 功能:数组名作为函数参数,求平均成绩。#include"stdio.h"floataver(floata[]){inti;floatav,s=a[0];for(i=1;i<5;i++)/***********SPACE***********/s+=【?】[i];av=s/5;/***********SPACE***********/return【?】;}voidmain(){floatsco[5],av;inti;printf(" input5scores: ");for(i=0;i<5;i++)/***********SPACE***********/scanf("%f",【?】);/***********SPACE***********/av=aver(【?】);printf("averagescoreis%5.2f ",av);}
- include stdio h define SUM 100000int main float amount aver total int i for i 1 total 0 i 1000 i printf please enter amount scanf f amount total total amount if total SUM break aver total i printf num d naver 10 2f n i aver return 0
- 设数组a中的元素均为正整数,以下程序是求a中偶数的个数和偶数的平均值。请填空。# include< stdio.h>int main( ){ int a[10]={1,2,3,4,5,6,7,8,9,10};int k,s,i;float ave;for(k=s=i=0;i<10;i++){ if(a[i]%2 !=0)( );s+=( );k++;}if( k!=0 ){ ave = s/k;printf("%d,% f\n",k,ave);}return 0;}
- 【单选题】下面程序执行后的输出结果是()。#include <stdio.h>int main(){int i=0,s=0;for (;;) {if(i==3||i==5) continue;if (i==6) break;i++; s+=i;};printf("%d",s); return 0;}#include <stdio.h>int main(){int i=0,s=0;for (;;) {if(i==3||i==5) continue;if (i==6) break;i++; s+=i;};printf("%d",s); return 0;}#include <stdio.h>int main(){int i=0,s=0;for (;;) {if(i==3||i==5) continue;if (i==6) break;i++; s+=i;};printf("%d",s); return 0;}#include <stdio.h>int main(){int i=0,s=0; A. 10 B. 13 C. 21 D. 死循环