【程序填空题_2】给定程序中,函数fun的功能是:把形参n中,各位上为为偶数的数取出,并按原来从高位到低位的顺序组成一个新的数,并作为函数值返回。
例如,从主函数输入一个整数:27638496,函数返回值为:26846。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <stdio.h> void fun(char *s) { int i, n, k; char c; n=0; for(i=0; s[i]!='\0'; i++) n++; /**********found**********/ if(n%2==0) k=n-___1___ ; else k=n-2; /**********found**********/ c=___2___ ; for(i=k-2; i>=1; i=i-2) s[i+2]=s[i]; /**********found**********/ s[1]=___3___ ; } main() { char s[80]="abcdefgh"; printf("\nThe original string is : %s\n",s); fun(s); printf("\nThe result is : %s\n",s); } |
【程序修改题_2】给定程序MODI1.C中函数fun的功能是:输出M行M列整数方阵,然后求两条对角线上元素之和,返回此和数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <stdio.h> long fun (int a, int n) { int j ; /**************found**************/ long s = 0, t = 1 ; for ( j = 0 ; j < n ; j++) t = t * 10 + a ; s = t ; for ( j = 1 ; j < n ; j++) { /**************found**************/ t = t % 10 ; s = s - t ; } return(s) ; } main( ) { int a, n ; printf( "\nPlease enter a and n:") ; scanf( "%d%d", &a, &n ) ; printf( "The value of function is: %ld\n", fun ( a, n ) ); } |
【程序设计题_2】函数fun的功能是:将a、b中的两个正整数合并形成一个新的整数放在c中。合并的方式是:将a中十位和个位数依次放在变量c的千位和十位上,b中的十位和个位数依次放在变量c的个位和百位上。
例如,当a=45,b=12。调用函数后,c=4251。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include <stdio.h> #include <string.h> void fun(char *tt, int pp[]) { } main( ) { char aa[1000] ; int bb[26], k ; printf( "\nPlease enter a char string:" ) ; scanf("%s", aa) ; fun(aa, bb ) ; for ( k = 0 ; k < 26 ; k++ ) printf ("%d ", bb[k]) ; printf( "\n" ) ; } |