#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; }
Q1:提供随机数
Q2:生成学号
#include <stdio.h> #include <stdlib.h> int main() { int a, b, i; a = rand() % 30; printf("猜猜2022年11月哪一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1-30):"); for (i = 1; i <= 3; i++) { scanf_s("%d", &b); printf("\n"); if (a == b) { printf("哇,猜中了:-)\n"); break; } else if (a > b) { printf("你猜的日期早了,你的lucky day还没到呢\n\n"); if(i<3)printf("再猜(1-30):"); } else { printf("你猜的日期晚了,你的luvky day已经过啦\n\n"); if (i < 3)printf("再猜(1-30):"); } } if (i >3) { printf("\n\n\n次数用完啦,偷偷告诉你:11月,你的lucky day是%d号", a); } return 0; }
#include<stdio.h> #include<stdlib.h> int main() { char a; while (a = getchar(), a != EOF) { getchar(); switch (a) { case'y':printf("wait a minate\n"); break; case'g':printf("go go go\n"); break; case'r':printf("stop!\n"); break; default:printf("something must be wrong...\n"); break; }
} return 0; }
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int a, n,k; double s ,p,b; while(scanf_s("%d%d",&n,&a)!=EOF) { for (k = 1,b=a,s=0;k<=n;k++) { p = k / b; s += p; b +=pow(10,k)*a; } printf("n=%d,a=%d,s=%f\n\n", n, a, s); } return 0; }
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int i,j,k; for(i=1;i<=9;i++) { for (j = 1; j <= i; j++) { k = i * j; printf("%dx%d=%2d ", j, i, k); }printf("\n"); } return 0; }
#include<stdio.h> #include<stdlib.h> int main() { int i,j,k,n; scanf_s("%d",&n); for (i = 1; i <= n; i++) { for (j = 1; j <= i - 1; j++) printf(" "); for (k = 1; k <= 2 * (n + 1 - i) - 1; k++) printf(" O "); printf("\n"); for (j = 1; j <= i - 1; j++) printf(" "); for (k = 1; k <= 2 * (n + 1 - i) - 1; k++) printf("<H> "); printf("\n"); for (j = 1; j <= i - 1; j++) printf(" "); for (k = 1; k <= 2 * (n + 1 - i) - 1; k++) printf("I I "); printf("\n\n"); } return 0; }
2(n-i)+1`个小人
5(i-1)个空格
. 标签:include,int,number,break,实验,printf,main From: https://www.cnblogs.com/scx3044391/p/16804909.html