#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:随机生成一个范围在1~500以内的整数
2:随机生成5个学号
二
#include <stdio.h> #include <stdlib.h> #include <time.h> #define a 1 #define b 31 int main () { printf("猜猜2022年11月那一天会是你的lucky day\n开始喽,你有三次机会:"); srand ((int)time(0)); int num = rand()%(b-a+1)+a; int usernum; int f = 0; for (int i = 0;i<3;i++) { f++; scanf("%d%*c",&usernum); if (usernum > num) printf("你猜的日期晚了,你的lucky day已经过了\n"); if (usernum < num) printf("你猜的日期早了,你的lucky day已经过了\n"); if (usernum == num) { printf("哇,猜中了:-)\n"); break; } if (i<2) printf("再猜:"); } if ( f == 3) { printf("\n"); printf("\n次数用完啦。偷偷告诉你:11月,你的lucky day是%d号",num); } return 0; }
3
#include<stdio.h> int main() { char i; char c; do { scanf_s("%c", &i); if (i == 'r') printf("stop\n"); else if (i == 'g') printf("go\n"); else if (i == 'y') printf("wait\n"); else if (i!='r'&&i!='y'&&i!='g') printf("wrong\n"); } while ((c= getchar( )) != EOF); return 0; }
四
#include <stdio.h> #include <math.h> int main() { int n, a; int p = 0; double sum = 0; char ch; int i; do { scanf_s("%d %d", &n, &a); for (i = 1; i <= n; i++) { p += a * pow(10, (i - 1)); sum += (double)i / p; } printf("n=%d, a=%d, s = %f\n", n, a, sum); p = 0; sum = 0; } while ((ch = getchar()) != EOF); return 0; }
五
#include <stdio.h> #include <math.h> int main() { int mul; for (int i = 1;i < 10;i++) { for(int k = 1;k<=i;k++) { mul = i * k; printf("%dx%d = %2d ",k,i,mul); if (i == k) printf("\n"); } } return 0; }
六
#include <stdio.h> int main() { int n; printf("input n :"); scanf_s("%d", &n); int total = 2 * n - 1; for (int i = 0; i < n; i++) { for (int k = 1; k <= total; k++) { if (k > i && k < 2 * n - i) printf(" O\t"); else printf("\t"); if (k == total) printf("\n"); } for (int k = 1; k <= total; k++) { if (k > i && k < 2 * n - i) printf("<H>\t"); else printf("\t"); if (k == total) printf("\n"); } for (int k = 1; k <= total; k++) { if (k > i && k < 2 * n - i) printf("I I\t"); else printf("\t"); if (k == total) printf("\n"); } printf("\n"); } return 0; }
第i行需要打印 (2n-2i+1)个小人
第i行前面需要打印(i-1)个空格
标签:include,int,else,实验,&&,printf,main From: https://www.cnblogs.com/liangchenxi/p/16826846.html