printf(\ s = fun(n);
printf(\ }
41、double fun(int n) { int i;
float s=1.0, t=1.0; for(i=2;i<=n;i++) { t=t+i; s=s+1/t; }
return s; }
42、请编写函数fun, 函数的功能是:统计一行字符串中单词的个数,作为函数值返回。一行字符串在主函数中输入, 规定所有单词由小写字母组成,单词之间由若干个空格隔开, 一行的开始没有空格。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容, 仅在函数fun的花括号中填入你编写的若干语句。
#include #include #define N 80 int fun( char *s) { } main()
{ char line[N]; int num=0;void
printf(\ num=fun( line );
printf(\ }
42、int fun( char *s) {
int i=0,j=0,f=1; while(s[i]) {
if(s[i]<'a' || s[i]>'z') {
if(f) j++; f=0; } else f=1; i++; }
43、请编写函数fun,函数的功能是:统计各年龄段的人数。N个年龄通过调用随机函数获得,并放在主函数的age数组中;要求函数把0至9岁年龄段的人数放在d[0]中,把10至19岁年龄段的人数放在d[1]中,把20至29岁年龄段的人数放在d[2]中, 其余依此类推, 把100岁 (含100)以上年龄的人数都放在d[10]中。结果在主函数中输出。 注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include #define N 50 #define M 11
void fun( int *a, int *b) { }
double rnd()
{ static t=29,c=217,m=1024,r=0; r=(r*t+c)%m; return((double)r/m); } main()
{ int age[N], i, d[M];void
for(i=0; i printf(\ for(i=0;i printf(\ fun( age, d);
for(i=0;i<10;i++)printf(\ printf(\ }
43、void fun( int *a, int *b) { int i,k;
for(i=0;i for(i=0;i { k=a[i]/10; if(k>=10) b[10]++; else b[k]++; }
}
44、程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun( int a[][N]),函数的功能是:使数组左下三角元素中的值全部置成0 。例如:a 数组中的值为 | 1 9 7 | | 0 9 7 |
a = | 2 3 8 | 则返回主程序后a数组中的值应为 | 0 0 8 | | 4 5 6 | | 0 0 0 |
注意: 部分源程序存在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include #include #define N 5 void fun ( int a[][N] ) { } main ( ) { void
int a[N][N], i, j;
printf(\
for ( i =0; i { for ( j =0; j { a[i][j] = rand(); printf( \a[i][j] ); } printf(\ }
fun ( a );
printf (\
for ( i =0; i { for ( j =0; j printf(\ } }
44、void fun ( int a[][N] ) { int i,j;
for(i=0;i for(j=0;j<=i;j++) a[i][j]=0; }
45、程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun,函数的功能是:使数组右上三角元素中的值乘以m 。 例如:若m的值为2,a 数组中的值为 | 1 9 7 | | 2 18 14|
a = | 2 3 8 | 则返回主程序后a数组中的值应为 | 2 6 16|
| 4 5 6 | | 4 5 12|
注意: 部分源程序存在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容, 仅在函数fun的花括号中填入你编写的若干语句。
#include #include #define N 5 void fun ( int a[][N], int m ) { } main ( )
{ int a[N][N], m, i, j;void
printf(\
for ( i =0; i { for ( j =0; j { a[i][j] = rand() ; printf( \a[i][j] ); } printf(\ }
do m = rand() ; while ( m>=3 ); printf(\ fun ( a ,m );
printf (\
for ( i =0; i { for ( j =0; j printf(\ } }
45、void fun ( int a[][N], int m ) {
int i,j;
for(i=0;i for(j=i;j a[i][j]*=m; }
46、程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[][N], int n),函数的功能是:使数组左下三角元素中的值乘以n 。例如:若n的值为3,a 数组中的值为
| 1 9 7 | | 3 9 7 |
a = | 2 3 8 | 则返回主程序后a数组中的值应为 | 6 9 8 | | 4 5 6 | | 12 15 18|
注意: 部分源程序存在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include #include #define N 5 void fun ( int a[][N], int n )
相关推荐: