int a[4][4]={{1, 2, 3, 4}, {0, 2, 4, 5}, {3, 6, 9, 12}, {3, 2, 1, 0}}; printf(\
}
23.写出下面程序执行后的运行结果。 # include
void reverse(int a[], int n) {
int i, t;
for(i=0; i t=a[i]; a[i]=a[n-1-i]; a[n-1-i]=t; } } void main() { int b[10]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; reverse(b, 8); for(i=6; i<10; i++) s+=b[i]; printf(\} 24.将下面两个C源程序文件放到一个C项目中编译运行,程序运行时从键盘上输入:Thank回车,写出程序的运行结果。 a1.c文件如下: void fun1(); void fun2(); int M; void main() { M=102; fun1(); fun2(); } a2.c文件如下: #include char s[80], c; int n=0; while((c=getchar())!='\\n') s[n++]=c; n--; while(n>=0) printf(\} void fun2() { printf(\} 五、程序判断题 1.下面函数add的功能是求两个参数的和。判断下面程序的正误,如果有错误请改正过来。 void add(int a, int b) { int c; c=a+b; return ( c ); } 2.下面函数fun的功能是根据整型形参m,计算如下公式的值: y?1111???...? 100*100200*200300*300m*m判断下面程序的正误,如果有错误请改正过来。 fun( int m) { double y=0, d; int i; for(i=100, i return ( y ); } 3.下面函数fun的功能是将长整型数中偶数位置上的数依次取出,构成一个新数返回,例如,当s中的数为87653142时,则返回的数为8634。判断下面程序的正误,如果有错误请改正过来。 long fun(long s) { long t=0, s1=1; int d; while (s>0) { d=s; if (d%2=0) { t=d*s1+t; s1*=10; } s/=10; } return ( t ); } 4.下面函数fun的功能是依次取出字符串中所有数字字符,形成新的字符串,并取代原字符串。判断下面程序的正误,如果有错误请改正过来。 void fun (char s[]) { int i, j; for (i=0, j=0; s[i]!='\\0'; i++) if(s[i]>='0' && s[i] <='9') s[j]=s[i]; s[j]='\\0'; } 5.下面函数fun的功能是统计字符串s中各元音字母(即A,E,I,O,U)的个数(注意:字母不分大、小写)。判断下面程序的正误,如果有错误请改正过来。 void fun (char s[], int num[5]) { int k, i=5; for (k=0; k for(k=0; s[k]; k++) { i=-1; switch(s[k]) { case 'a' : case \ case 'e' : case \ case 'i' : case \ case 'o' : case \ case 'u' : case \ } if (i>=0) num[i]++; } } 六、程序填空题 1.下面函数的功能是计算函数F(x,y,z)?# include float x, y, z, f ; scanf(\ f=fun(【______________】); f+=fun(【______________】); printf(\} float fun(float a, float b) { return (a/b); x?yz?y?。请填空使程序完整、正确。 x?yz?y} 2. 下面函数的功能是键入10个整数,统计其中正数(neg)、负数(pos)和零(zero)的个数并将三者输出。请填空使程序完整、正确。 #include int neg=0, pos=0, zero=0; void self(int num) { if(num>0) neg++; else if(num<0) pos++; else 【______________】; } x2x3xn??...?3.下面sum函数的功能是计算S?1?x?级数之和并返回。请填空使程序完整、2!3!n!正确。 double sum(double x, int n) { int i; double a, b, s; 【______________】; for(i=1; i<=n; i++) { a=a*x; b=b*i; s=s+a/b; } 【______________】; } return min; } 4.下面函数的功能是调用函数fun得到两个数中的最大值。请填空使程序完整、正确。 #include 【______________】(double , double ); void main() { double x, y; scanf(\printf(\} double fun(double a, double b) { return (a>b ? a : b); } 5.下面函数用“折半查找法”从有10个数的a数组中对关键字m查找,若找到,返回其下标值,否则返回-1。请填空使程序完整、正确。 int search(int a[10], int m) { int x1=0, x2=9, mid; while (x1<=x2) { mid=(x1+x2)/2; if(ma[mid]) 【______________】; else return (mid); } return (-1); } 6.del函数的作用是删除有序数组a中的指定元素x,n为数组a的元素个数,函数返回删除以后的数组a元素的个数。请填空使程序完整、正确。 int del (int a[10], int n, int x) { int p=0, i; while (x>=a[p] && p 【______________】; return (n-1); } 7.avg函数的作用是计算数组array的平均值返回。请填空使程序完整、正确。 float avg(float array[10]) { int i; float avgr, sum=0; for (i=1; 【______________】; i++) sum+=【______________】; avgr=sum/10; 【______________】; } 8.下面函数的作用是通过递归的方法将字符串倒置。请填空使程序完整、正确。 void fun(char s[], int l, int h) { if(【______________】) return; else { char t; fun(【______________】); t=s[l], s[l]=s[h], s[h]=t; } } 9.下面函数的作用是求任意阶多项式a0+a1x+a2x2+…+an-1xn-1的值并返回多项式的值。请填空使程序完整、正确。 float fun(float a[], int n, int x) { float y, t=1; int i; y=【______________】; 搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新教育文库第八章 函数 (4)全文阅读和word下载服务。
相关推荐: