A类
1.(卷1题31搬运)以下程序的运行结果为:
#include <stdio.h>
void swap(char *a, char *b) {
char temp;
temp = *a;
*a = *b;
*b = temp;
}
int main() {
char a[] = "abc";
char b[] = "123";
swap(a, b);
printf("%s,%s\n", a, b);
return 0;
}
B类
2.(卷1题30搬运)
3.(原创)请编写一个程序,用户输入若干个正整数(输入-1表示结束),计算这些数的方差
运行效果:
--------------------------------以下为答案-------------------------------------
1. 1bc,a23
2. C (\0无法复制)(这题我也写错咯T_T)
3.
#include <stdio.h>
int main() {
int input, count = 0;
double ex, ex2, dx;
ex = ex2 = 0;
while(1) {
scanf("%d", &input);
if (input == -1) break;
ex += input;
ex2 += input * input;
count++;
}
ex /= count;
ex2 /= count;
dx = ex2 - ex * ex;
printf("%lf\n", dx);
return 0;
}