实验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 x, y, i; printf("猜猜2022年11月哪一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1-30):"); srand(time(0)); y = rand() % 30 + 1; for (i = 1; i <= 3; ++i) { if (i <= 3) { scanf_s("%d", &x); if (x == y) { printf("哇,猜中了:-)"); break; } else if (x > y) { printf("你猜的日期晚了,你的lucky day 已经过啦\n"); if (i <= 2) printf("再猜(1-30):"); } else if (x < y) { printf("你猜的日期早了,你的lucky day还没到呢\n"); if (i <= 2) printf("再猜(1-30):"); } } } printf("\n次数用完了。偷偷告诉你:11月,你的lukcy day是%d号", y); return 0; }
实验3
#include<stdio.h> #include<stdlib.h> int main() { char colour; while(scanf("%c",&colour)!=EOF) { switch(colour) { case 'y':printf("wait a minute\n");getchar();break; case 'g':printf("go go go\n");getchar();break; case 'r':printf("stop\n");getchar();break; default:printf("something must be wrong\n");getchar();break; } } return 0; }
实验4
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int n, a, i; while (scanf_s("%d%d", &n, &a) != EOF) { int j = 0; double s = 0; for (i = 1; i <= n; ++i) { j = j * 10 + a; s += (double)i / j; } printf("n=%d,a=%d,s=%f\n", n, a, s); } return 0; }
实验5
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int i,j,z; for (i = 1; i <= 9; i++) { for (j = 1; j <= i; j++) { z = i * j; printf("%d*%d=%d", i, j, z); printf("\t"); } printf("\n"); } return 0; }
实验6
#include<stdio.h> int main() { int i, j, k, n; printf("input n;"); scanf_s("%d", &n); for (i = 1; i <= n; i++) { for (j = 0; j < i - 1; j++) { printf("\t"); } for (k = 0; k < 2 * (n - i) + 1; k++) { printf(" o \t"); }printf("\n"); for (j = 0; j < i - 1; j++) { printf("\t"); } for (k = 0; k < 2 * (n - i) + 1; k++) { printf("<H>\t"); }printf("\n"); for (j = 0; j < i - 1; j++) { printf("\t"); } for (k = 0; k < 2 * (n - i) + 1; k++) { printf("I I\t"); }printf("\n"); } return 0; }
标签:include,int,实验,printf,main,getchar From: https://www.cnblogs.com/yaj030820/p/16804933.html