1. #include<stdio.h> #include<stdlib.h> #include<time.h> #define N 5 int main() { int number; int i; srand(time(0)); for (i = 0; i < N; i++) { number = rand() % 500 + 1; printf("20228329%04d/n", number); } return 0; } 2. #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int y; int i; srand(time(0)); int x = rand() % 31+1; printf("猜猜2022年11月那天是你的lucky day,开始了,你有三次机会,猜吧:"); for (i = 1; i < 4; i++) { scanf_s("%d", &y); if (y == x) { printf("哇,猜中了"); return 0; } else if (y < x) printf("你猜的日期早了,你的lucky day还没到呢!再猜"); else printf("你猜的日期晚了,你的lucky day已经过了,再猜"); } if (i >= 4) printf("次数用完了,偷偷告诉你吧,11月%d", x); return 0; }3. #include<stdio.h> int main() { char color; printf("请输入交通信号灯颜色:r表示red,g表示green,y表示yellow\n"); while (scanf_s("%c", &color) != EOF) { getchar(); switch (color) { 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; } } return 0; } 4. #include<stdio.h> int main() { int n,a; double k = 0; double p,i; double s = 0; while (scanf_s("%d,%d", &n, &a) != EOF) { for (i = 1; i <= n; i++) { k = k * 10 + a; p = i / k; s = s + p; } printf("%lf", s); } return 0; } 5. #include<stdio.h> #include<stdlib.h> int main() { unsigned int n, m, ans; int k, i, p; n = 0, m = 1, p = 1; ans = m * n; for (k = 1; k <= 9; ++k, ++p) { n = 0; for (i = 1; i <= p; ++i) { n++; ans = n * m; printf("%dx%d=%2d ", n, m, ans); } m++; printf("\n"); } system("pause"); return 0; } 6. #include<stdio.h> #include<stdlib.h> int main() { int n,i ,j,k,c,b,l; printf("input n:"); scanf_s("%d",&n); k=0,b=0,l=0; for(j=1;j<=n;n--) { for(c=1;c<=k;c++) {printf(" ");} for(i=1;i<=2*n-1;i++) { printf(" o \t"); } printf("\n"); for(c=1;c<=b;c++) {printf(" ");} for(i=1;i<=2*n-1;i++) { printf(" <H> \t"); } printf("\n"); for(c=1;c<=l;c++) {printf(" ");} for(i=1;i<=2*n-1;i++) { printf(" I I \t");} printf("\n"); }
标签:include,int,scanf,break,实验,printf,main From: https://www.cnblogs.com/wcf8/p/16826748.html