printf(\ : %s , %d\\n\}
第二题:
下列给定程序中,函数fun的功能是:将字符串p中的所有字符复制到字符串b中,要求每复制三个字符之后插入一个空格。例如,在调用fun函数之前给字符串a输入ABCDEFGHIJK,调用函数之后,字符串之后,字符串b 中的内容则为ABC DEF GHI JK。 请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include
int i, k = 0; while (*p) {
/********found********/ i = 0;
/********found********/ while (i<3 && *p) {
b[k] = *p; k++; p++; i++; }
/********found********/ if (*p)
b[k++] = ' '; }
b[k] = '\\0'; }
main() {
char a[80], b[80];
printf(\ \ gets(a);
printf(\ \ puts(a); fun(a, b);
printf(\ \ puts(b);
printf(\}
第三题:
请编写一个函数fun,它的功能是:计算并输出给定整数n的所有因子(不包括1与自身)之和。规定n的值不大于1000。
例如,若主函数从键盘给n输入的值为856,则输出为sum=763。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 #include
int fun(int n) { }
main() {
int n,sum; FILE *out ;
printf(\ \ scanf(\ sum=fun(n);
printf(\ out=fopen (\ fprintf(out, \ fprintf(out, \ fprintf(out, \ fprintf(out, \ fprintf(out, \ fclose (out ); }
int fun(int n) {
int s=0,i;
for(i=2;i<=n-1;i++) if(n%i==0) s+=i; return s; }
第4套
填空题
请补充main函数,该函数的功能是:把字符串str1中的非空格字符拷贝到字符串str2中.
例如,若str1=”nice to meet you!”,则str2=”nicetomeetyou!”
仅在横线上填入所编写的若干表达式或语句,勿改动函数中的其他任何内容.
#include
static char str1[N] = \ char str2[N]; int i = 0, j = 0;
printf(\ puts(str1); while (str1[i]) {
if (___1___)
str2[j++] = str1[i]; ___2___; }
printf(\ for (i=0; i printf(\} 改错题 下列给定程序中,函数fun的功能是:将大写字母转换为对应小写字母之后的第五个字母;若小写字母为v~z,使小写字母的值减21.转换后的小写字母作为函数值返回.例如,若形参是字母A,则转换字母为小写字母f;若形参是字母W,则转换为小写字母b. 请改正函数fun中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! #include /********found********/ if (c>='A' && c<='Z') c = c-32; /********found********/ if (c>='a' && c<='u') c = c-5; else if (c>='v' && c<='z') c = c-21; return c; } main() { char c1, c2; printf(\ \ c1 = getchar(); if (isupper(c1)) { c2 = fun(c1); printf(\ } else { printf(\ } } 编程题 请编写函数fun,其功能是:将s所指字符串中ASCII值为奇数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。 例如,若s所指字符串中的内容为ABCDEFG12345,其中字符A的ASCII码值为奇数、……、 字符1的ASCII码值也为奇数、……都应当删除,其他依次类推。最后t所指的叔祖中的内容应是BDF24。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 #include void fun( char *s, char t[]) { } main() { char s[100], t[100], Msg[] = \ FILE *out ; printf(Msg); scanf(\ fun(s, t); printf(\ out=fopen (\ fun(Msg, t); fprintf(out, \ fclose (out ); } 答案: 第一题: 第1处填空str1[i]!=’ ’或’ ’!= str1[i] 第2处填空i++或++i或i+=1或i=i+1 第二题: 第1处:c=c-32;应改为c=c+32; 第2处:c=c-5; 应改为 c=c+5; 第三题: void fun (char*s,char t[]) { int I, j=0, n; n=strlen(s); for(i=0;i t[j]=s[i]; j++; } t[j]=’\\0’ } 第5套 填空题 请补充main函数,该函数的功能是:输出一个N*N矩阵,要求非周边元素赋值0,周边元素赋值1。 仅在横线上填入所编写的若干表达式或语句,勿改动函数中的其他内容。
相关推荐: