所属年份:2010.9;2011.9;2012.3;
【程序填空题】
给定程序中,函数fun的功能是:统计形参s所指的字符串中数字字符出现的次数,并存放在形参t所指的变量中,最后在主函数中输出。例如,若形参s所指的字符串为"abcdef35adgh3kjsdf7",则输出结果为4。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <stdio.h> void fun(char *s, int *t) { int i, n; n=0; /**********found**********/ for(i=0; ___1___ !=0; i++) /**********found**********/ if(s[i]>='0'&&s[i]<= ___2___ ) n++; /**********found**********/ ___3___ ; } main() { char s[80]="abcdef35adgh3kjsdf7"; int t; printf("\nThe original string is : %s\n",s); fun(s,&t); printf("\nThe result is : %d\n",t); } |
【程序修改题】
下列给定程序中函数fun的功能是:实现两个变量值的交换,规定不允许增加语句和表达式。
例如,变量a中的值原为8,b中的值原为3,程序运行后a中的值为3,b中的值为8。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <stdio.h> int fun(int *x,int y) { int t ; /**************found**************/ t = x ; x = y ; /**************found**************/ return(y) ; } main() { int a = 3, b = 8 ; printf("%d %d\n", a, b) ; b = fun(&a, b) ; printf("%d %d\n", a, b) ; } |
【程序设计题】
编写函数fun,其功能是:求出1~1000之间能被7或11整除,但不能同时被7和11整除的所有整数,并将其放在a所指的数组中,通过n返回这些数的个数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <stdio.h> void fun (int *a, int *n) { } main( ) { int aa[1000], n, k ; fun ( aa, &n ) ; for ( k = 0 ; k < n ; k++ ) if((k + 1) % 10 == 0) printf("\n") ; else printf("%5d", aa[k]) ; } |