#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之间取一个数字且包括500
问题二:随机生成一串数字
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int number; int n; int i; srand(time(0)); number = rand() % 30 + 1; printf("猜猜那一天会是你的Lucky day\n"); printf("开始喽,你有三次机会,猜吧(1~30):\n"); for (i = 1; i <= 3; i++) { scanf("%d", &n); getchar(); if (n == number) { printf("你猜中了"); break; } if (n < number) { printf("你猜的日期早了,Lucky day还没到呢\n"); } if (n > number) { printf("你猜的日期晚了,Lucky day已经过啦\n"); } if (i == 3) { printf("次数用光啦,偷偷告诉你:11月,你的Lucky day是%3d号\n", number); break; } if (i <= 2) { printf("再猜:\n"); } } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { char x; while (scanf(" %c", &x) != EOF) { switch (x) { case 'r':printf("stop\n"); break; case 'g':printf("gogogo\n"); break; case 'y':printf("wait a moment\n"); break; default:printf("something must be wrong \n"); } } return 0; }
#include<stdio.h> #include<math.h> int main() { int n, a, b; double s, c; while (scanf_s("%d,%d", &n, &a) != EOF) { b = n; c = a; n = 1; for (s = 0; n <= b; ++n) { s = s + n / c; c = 10 * c + a; } printf("n=%d,a=%d,s=%f\n", b, a, s); printf("\n"); } return 0; }
#include<stdio.h> int main() { int a, b; for (a = 1; a <= 9; a++) { for (b = 1; b <= a; b++) printf("%dx%d=%2d ", b, a, a * b); printf("\n"); } }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main() { int i, m, n; scanf("%d", &n); for (i = 1; i <= n; i++) { for (m = 1; m < i; m++) { printf(" \t"); } for (m = 1; m <= 2 * (n - i) + 1; m++) { printf(" O \t"); } printf("\n"); for (m = 1; m < i; m++) { printf(" \t"); } for (m = 1; m <= 2 * (n - i) + 1; m++) { printf("<H>\t"); } printf("\n"); for (m = 1; m < i; m++) { printf(" \t"); } for (m = 1; m <= 2 * (n - i) + 1; m++) { printf("I I\t"); } printf("\n"); printf("\n"); } return 0; }
标签:include,int,number,实验,printf,main,define From: https://www.cnblogs.com/sjj66/p/16824447.html