在考生文件夾下,給定程序MODI.C的功能是:
求一維數(shù)組a中值為奇數(shù)的元素之和。
例如,當一維數(shù)組a中的元素為:10,4,2,7,3,12,5,34,5,9, 21 ,19
程序的輸出應(yīng)為:The result is: 69。
#include
#include
int sum( int b[ ],int n )
{
int i,s = 0;
for ( i=0; i if (b[i] % 2 == 1) /************found************/
s=s+b[i];
s = s + b[i]
return (s);
}
main()
{
int a[12]={10,4,2,7,3,12,5,34,5,9,21,19},n;
sum(a,12); |
sum(a,2);
printf("The result is :%d\n",n );
}
2015年全國職稱計算機考試教材(2007模 .. 定價:¥225 優(yōu)惠價:¥213 更多書籍 | |
全國職稱計算機考試速成過關(guān)系列套裝:W .. 定價:¥133 優(yōu)惠價:¥133.0 更多書籍 |