3道C语言题

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/11 01:01:10

3道C语言题
3道C语言题


3道C语言题
#include <stdio.h>

int main() {
char cx, front = '\0';
while ((cx = getchar()) != '\n') {
if (cx != ' ') putchar(cx);
if (cx == ' ')
if (front != ' ')
putchar(cx);
front = cx;
}
}#include <stdio.h>

int main() {
int m, n, mul, t;
scanf("%d %d", &m, &n);
mul = m * n;
while (n != 0) {
t = m % n;
m = n;
n = t;
}
mul /= m;
printf("最大公约数: %d 最小公倍数 %d\n", m, mul);
}#include <stdio.h>

int main() {
char c;
int space = 0, alpha = 0, number = 0, others = 0;
while ((c = getchar()) != '\n') {
if (c == ' ') {
space++;
}
else if (c >= '0' && c <= '9') {
number++;
}
else if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
alpha++;
}
else {
others++;
}
}
printf("英文字母: %d\n空格: %d\n数字: %d\n其他: %d\n", alpha, space, number, others);
}#include <stdio.h>

int main() {
long long sum = 0;
long long mul = 1;
int i;
for (i = 1; i <= 20; i++) {
mul *= i;
sum += mul;
}
printf("1! + 2! + 3! + ... + 19! + 20! = %lld\n", sum);
}