3.求最大公约数和最小公倍数
int main() {
int n = 0;
int a =0 , b = 0,t=0;
start: scanf("%d,%d", &a, &b);
if (a == 0 || b == 0){
printf("a和b不能为0 \n");
goto start;
}
else{
if (a < b){
t = a;
a = b;
b = t;
}
int sum = a*b;
t = a%b; //先算一下
while (t != 0){
a = b;
b = t;
t = a%b;
}
printf("最大公约数:%d,最小公倍数%d\n", b, sum / b);
}
}
4.统计
#include <iostream>
int main() {
int n = 0;
char c;
int y, k, s, q;
y = k = s = q = 0;
printf("输入一行字符,按回车结束\n");
c = getchar();
while (c != '\n'){
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')){
y++;
}
else if (c == ' '){
k++;
}
else if (c >= '0'&&c <= '9'){
s++;
}
else q++;
c = getchar();
}
printf("英文字母:%d \n空格:%d \n数字:%d \n其他:%d\n", y, k, s, q);
return 0;
}