1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 #define N 5 5 int main() 6 { 7 int number; 8 int i; 9 srand(time(0)); 10 for(i=0;i<N;i++){ 11 number=rand()%500+1; 12 printf("20228329%d04\n",number); 13 } 14 return 0; 15 }
一:在1—500之间取一个数字
二:随机生成一串数字
1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <time.h> 5 6 int main() 7 { 8 int number; 9 int n; 10 int i; 11 12 srand(time(0)); 13 number = rand() % 30 + 1; 14 printf("猜猜那一天会是你的Lucky day\n"); 15 printf("开始喽,你有三次机会,猜吧(1~30):\n"); 16 for (i = 1; i <= 3; i++) 17 { 18 scanf_s("%d", &n); 19 getchar(); 20 21 if (n == number) 22 { 23 printf("你猜中了"); 24 break; 25 } 26 if (n < number) 27 { 28 printf("你猜的日期早了,Lucky day还没到呢\n"); 29 } 30 if (n > number) 31 { 32 printf("你猜的日期晚了,Lucky day已经过啦\n"); 33 } 34 if (i == 3) { 35 printf("次数用光啦,偷偷告诉你:11月,你的Lucky day是%3d号\n", number); 36 break; 37 } 38 if (i <= 2) { 39 printf("再猜:\n"); 40 } 41 } 42 43 44 return 0; 45 }
1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.h> 3 int main() 4 { 5 char x; 6 7 while (scanf_s(" %c", &x) != EOF) 8 { 9 switch (x) 10 { 11 case 'r':printf("stop\n"); break; 12 case 'g':printf("gogogo\n"); break; 13 case 'y':printf("wait a moment\n"); break; 14 default:printf("something must be wrong \n"); 15 16 } 17 18 } 19 return 0; 20 }
1 #include<stdio.h> 2 int main() 3 { 4 int i,j; 5 for(i=1;i<=9;i++) 6 { 7 for(j=1;j<=i;j++) 8 { 9 printf("%d*%d=%d",i,j,i*j); 10 printf(" "); 11 } 12 printf("\n"); 13 } 14 return 0; 15 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 #define _CRT_SECURE_NO_WARNINGS 5 int main() 6 { 7 int i, n, a, t; 8 9 while (scanf_s("%d %d", &n, &a) != EOF) 10 { 11 double s = 0, t = 0; 12 for (i = 1; i <= n; i++) 13 { 14 t = 10 * t + a; 15 s = s + (double)i / t; 16 17 } 18 printf("n=%d,a=%d,s=%f\n", n, a, s); 19 20 } 21 return 0; 22 }
1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.h> 3 int main() 4 { 5 int i, m, n; 6 scanf("%d", &n); 7 for (i = 1; i <= n; i++) { 8 for (m = 1; m < i; m++) { 9 printf(" \t"); 10 } 11 for (m = 1; m <= 2 * (n - i) + 1; m++) { 12 printf(" O \t"); 13 } 14 printf("\n"); 15 for (m = 1; m < i; m++) { 16 printf(" \t"); 17 } 18 for (m = 1; m <= 2 * (n - i) + 1; m++) { 19 printf("<H>\t"); 20 } 21 printf("\n"); 22 for (m = 1; m < i; m++) { 23 printf(" \t"); 24 } 25 for (m = 1; m <= 2 * (n - i) + 1; m++) { 26 printf("I I\t"); 27 } 28 printf("\n"); 29 printf("\n"); 30 } 31 return 0; 32 }
标签:include,int,number,实验,printf,main,define From: https://www.cnblogs.com/kennthy/p/16826580.html