task1
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 #define R1 586 #define R2 701 int main() { int number; int i; srand( time(0) ); for(i = 0;i < N; ++i) { number =rand() % (R2-R1 + 1) + R1; printf("20228330%04d\n", number); } return 0; }
生成五个586-701间的数
随机生成五个数
task2
#include<stdio.h> int main() { double x,y; char c1,c2,c3; int a1,a2,a3; scanf("%d%d%d",&a1,&a2,&a3); printf("a1=%d,a2=%d.a3=%d\n", a1,a2,a3); scanf("%c%c%c",&c1,&c2,&c3); printf("c1=%c,c2=%c.c3=%c\n",c1,c2,c3); scanf("%lf,%lf",&x,&y); printf("x=%lf,y=%lf\n",x,y); return 0; }
task3
#include<stdio.h> #include<math.h> int main() { double x,ans; while(scanf("%lf", &x) != EOF){ ans= pow(x,365); printf("%.2f的365次方:%.2f\n", x, ans); printf("\n"); } return 0; }
#include<stdio.h> #include<math.h> int main() { double c,f; while(scanf("%lf", &c) != EOF){ f= (double)9/5*c+32 ; printf("摄氏度为c=%.2f时,华氏度为f=%.2f\n", c, f); printf("\n"); } return 0; }
task4
#include<stdio.h> int main() { char ans; printf("输入信号灯的颜色,输入r表示red,输入g表示green,输入y表示yellow: "); while(scanf("%c", &ans)!= EOF) { getchar(); switch(ans) { case'r': printf("stop!\n");break; case'g': printf("go go go\n");break; case'y': printf("wait a minute\n");break; default: printf("something must be wrong...\n");break; } printf("输入信号灯的颜色,输入r表示red,输入g表示green,输入y表示yellow: "); } return 0; }
task5
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int ans; int lucky,i; srand(time(0)); lucky=rand()%30+1; printf("猜猜2023年4月哪一天是你的lucky day\n开始咯,你有三次机会,猜吧(1-30):"); for(i=1;i<=2;i++) { scanf("%d",&ans); if(ans<lucky) {printf("你猜的日期早了,你的lucky day还没到呢\n再猜(1-30):"); continue;} else if(ans>lucky) {printf("你猜的日期晚了,你的lucky day已经过了\n再猜(1-30):"); continue; } else if(ans=lucky) { printf("猜中了\n");break;} } if(ans!=lucky){ scanf("%d",&ans); if(ans!=lucky) { printf("次数用完啦,偷偷告诉你:你的lucky day是 %d 号",lucky );} else if(ans=lucky) { printf("猜中了\n");} } return 0; }
task6
#include<stdio.h> int main() { int i,n, m; for(i=1;i<=9;i++) { for(n=1;n<=i;n++) { m=n*i; printf("%d×%d = %d\t",n,i,m ); } if(n=i) printf("\n"); } return 0; }
task7
#include<stdio.h> #include<stdlib.h> int main() { int n,i,j; printf("input n:",n); scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<i;j++) printf("\t"); for(j=1;j<=2*(n-i)+1;j++) printf(" O \t"); printf("\n"); for(j=1;j<i;j++) printf("\t"); for(j=1;j<=2*(n-i)+1;j++) printf("<H>\t"); printf("\n"); for(j=1;j<i;j++) printf("\t"); for(j=1;j<=2*(n-i)+1;j++) printf("I I\t"); printf("\n"); } system("pause"); return 0; }
标签:main,int,printf,lucky,实验,ans,include From: https://www.cnblogs.com/Tzaa/p/17241645.html