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