编程新手猜数字游戏

#include <stdio.h>
#include <time.h>
#include<stdlib.h>
void main() {
srand(time(0));
int n = rand() % 100 + 1,c = 0,a = 0;
printf("我有一个1-100的随机数,你猜是多少:>");
do {
scanf("%d", &a);
c++; if
(a > n)printf("猜大了。\n");
else if
(a > 100) printf("小笨蛋,输错了。");
else if
(a < n)printf("猜小了。\n");
else
printf("6666666");
}
while (a != n);
printf("猜了%d次猜中\n", c);
system("pause");
}

C语言9*9口诀表

#include<stdio.h>
void main()
{
for (int i = 1; i < 10; ++i)
{
for (int t = 1; t <=i; ++t)
printf("%d%d=%d\t",i,t,it);
printf("\n");
}system("pause");
}

C语言求最大公约数

方法一:

#include<stdio.h>
int main(){
int t, num1, num2;
scanf("%d %d", &num1, &num2);
do{
t = num2;
num2 = num1%num2;
num1 = t;
} while (num2 != 0);
printf("%d\n", num1);
system("pause");
return 0;
}

方法二:

#include<stdio.h>
int main()
{
int num1, num2;
scanf("%d %d", &num1,&num2);
int min = num1 > num2 ? num2 : num1;
for (int i = min; i > 0;--i)
{
if (num1%i == 0 && num2%i == 0)
{
printf("%d与%d的最大公约数是:%d\n", num1, num2, i);
break;
}
}
system("pause");
return 0;
}