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