2.#include<stdio.h>//求最大公约数和最小公倍数 int main() { int a,b,m,i,n; n=1; printf("请输入你的两个数:"); scanf("%d %d",&a,&b); m=a; if(a<b){ a=b; b=m; } for(i=2;i<=b;i++) { if(a%i==0&&b%i==0) n=i; } printf("它们的最大公约数是:%d ",n); m=(a*b)/n; printf("它们的最小公倍数是:%d ",m); return 0; }
1.#include<stdio.h> #include<stdlib.h> #include<time.h> int main()//猜字游戏 { int mynumber,yournumber,count=0,N; srand((unsigned)time(NULL)); mynumber=(rand()%(101-1))+1; printf("请输入你的限制次数N: "); scanf("%d",&N) ; do{ printf("请输入你猜的数字: "); scanf("%d",&yournumber); count++,count<=N; if(yournumber>mynumber&&yournumber>0) printf("Too Big! "); else if(yournumber<mynumber&&yournumber>0) printf("Too Small! "); else if(yournumber<0) printf("Game Over! "); }while(yournumber!=mynumber); if(count==1) printf("Bingo!"); else if(2<=count<=3) printf("Luck You!"); else if(3<count<=N) printf("Good Guess!"); else if (count>N) printf("Game Over !"); printf("你一共输出了%d次 ",count); return 0; }