任务1
#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; }
任务2
#include <stdio.h> int main() { double x,y; char ans,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%c",&ans,&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); getchar(); return 0; }
任务3
#include <stdio.h> int main() { double c, f; while(scanf("%lf", &c) != EOF) { f = 9*c/5+32; printf("摄氏度c=%.2f时,华氏度f=: %.2f\n", c, f); printf("\n"); } return 0; }
任务4
#include <stdio.h> int main() { char c; while(scanf("%c", &c) != EOF) { switch(c){ case'y':printf("wait a minute\n");break; case'g':printf("go go go");break; case'r':printf("stop!");break; case'x':printf("something must be wrong");} }getchar(); return 0; }
任务5
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int x,n,i; srand(time(0)); x = rand() %(30)+1; printf("猜猜2023年4月哪一天会是你的lucky day\n开始喽,你有三次机会,"); for(i=0;i<3;i++){ printf("猜吧(1-30):"); scanf("%d",&n); if(n==x) {printf("哇,你中了!!!\n");break;} else if(n<x) printf("你猜的时间早了哦\n"); else printf("你猜的时间晚了哦\n"); if(i==2) printf("次数用完啦,偷偷告诉你,4月你的lucky day是%d号\n",x); } system("pause"); return 0; }
任务6
#include <stdio.h> int main() { for(int i=1;i<=9;i++){ for(int j = 1;j<=i;j++) printf("%d*%d=%-3d",j,i,j*i); printf("\n"); } return 0; }
任务7
#include <stdio.h> #include <stdlib.h> int main() { int n,i,x,y; scanf("%d",&n); y=1; for(;n!=0;n--){ for(x=1;x<y;x++){ printf("\t"); } for(i=1;i<=(2*n-1);i++){ printf(" o \t"); } printf("\n"); for(x=1;x<y;x++){ printf("\t"); } for(i=1;i<=(2*n-1);i++){ printf("<H>\t"); } printf("\n"); for(x=1;x<y;x++){ printf("\t"); } for(i=1;i<=(2*n-1);i++){ printf("I I\t"); } printf("\n"); y++; } return 0; }
标签:lf,include,int,scanf,实验,printf,main From: https://www.cnblogs.com/hanyumu/p/17245918.html