A类
1.(卷2题29搬运)执行以下程序
#include <stdio.h>
int main() {
int a;
float b;
char c[1000];
scanf("%2d%f%s", &a, &b, c);
printf("%f", b);
return 0;
}
运行后输入55566 7777123后,b的值为:
A.566.0 B.55566.0 C.7777.0 D.566777.0
2. (卷1题17易改难)以下程序的运行结果为:
#include <stdio.h>
int main() {
char c1, c2;
c1 = 'B' + '8' - '4';
c2 = 'a' + '8' - '3';
printf("%d,%c\n", c1, c2);
return 0;
}
注:字母A的ASCII码为65
B类
3.(卷1题四 搬运)请编写一个函数func,有一个int型参数,函数的功能是计算参数的所有因子之和,作为返回值返回。
例如,func(24)=1+2+3+4+6+8+12+24=60
4.(原创)请编写一个程序,要求用户输入一个字符串(只允许用gets()输入),去除其中所有字母a(仅小写),然后输出(只允许用puts()输出)。
【样例输入】An apple a day keeps the doctor away.
【样例输出】An pple dy keeps the doctor wy.
(提示:遍历字符串每个元素 ,遇到a则把后面所有元素向前移一格覆盖这个a)
--------------------------------以下为答案--------------------------------------
1. A
2. 70,f
3.
#include <stdio.h>
int func(int n) {
int sum = 0, i;
for (i = 1; i <= n; i++) {
if (n % i == 0) {
sum += i;
}
}
return sum;
}
int main() {
int n;
scanf("%d", &n);
printf("%d\n", func(n));
return 0;
}
4.
#include <stdio.h>
int main() {
char a[1000];
gets(a);
int i = 0, j;
while (a[i] != '\0') {
if (a[i] == 'a') {
for (j = i; j < 999; j++) {
a[j] = a[j+1];
}
}
i++;
}
puts(a);
return 0;
}