#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; }
随机取一个在1~501的数。用来抽签什么的。
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int i, j, m; srand(time(0)); j = rand() % 29 + 1; printf("猜猜2022年11月哪一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1~30):"); scanf_s("%d", &i); for (m = 1; m <= 2; m++) { if (i > j) { printf("你猜的日期晚了,你的lucky day已经过啦\n"); printf("再猜:"); scanf_s("%d", &i); } else if (i < j) { printf("你猜的日期早了,你的lucky day还没到呢\n"); printf("再猜:"); scanf_s("%d",&i); } else { printf("哇,猜中了:-)"); break; } } if (m == 3) { printf("次数用完啦,偷偷告诉你:11月,你的lucky day是%d", j); } return 0; }
#include<stdio.h> #include<stdlib.h> int main() { char a; while (scanf_s("%c",&a)!=EOF) { switch (a) { 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; } getchar(); } return 0; }
#include<stdio.h> #include<math.h> int main() { int n, a,b; double j, s = 0.0; while (scanf_s("%d%d", &n, &a) != EOF) { b = a; printf("n=%d,a=%d", n, a); for (j = 1.0; j <= n; j++) { s += j /b; b = b * 10 + a; } printf(" s=%lf\n", s); s = 0; } return 0; }
#include<stdio.h> int main() { int a, b,c; for (a = 1; a <= 9; a++) { for (b = 1; b <=a; b++) { c = b * a; printf("%d*%d=%d \t",b,a,c); } printf("\n"); } return 0; }
#include<stdio.h> int main() { int n,m,j,i,k,e=1; printf("input n:"); scanf_s("%d", &n); i = n; for (m = 1; m <= i; m++) { for (k = 1; k < e; k++) { printf("\t"); } for (j = 1; j <= (2 * n - 1); j++) { printf(" O \t"); } printf("\n"); for (k = 1; k < e; k++) { printf("\t"); } for (j = 1; j <= (2 * n - 1); j++) { printf("<H>\t"); } printf("\n"); for (k = 1; k < e; k++) { printf("\t"); } for (j = 1; j <= (2 * n - 1); j++) { printf("I I\t"); } printf("\n"); n = n - 1; e = e + 1; } return 0; }
标签:include,int,scanf,break,实验,printf,main From: https://www.cnblogs.com/lz34/p/16825985.html