#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 #define R1 586 #define R2 701 int main() { int number; int i; srand(time(0)); for(i=0;i<N;i++) { number=rand()%(R2-R1+1)+R1; printf("20228330%04d\n",number); } return 0; }
实验1:answer1:line18的作用生成从R1~R2范围的一个随机数
answer2:整个程序的作用是生成从586到700的任意5个随机数
#include <stdio.h> int main() { double x, y; char c1, c2, c3; int a1, a2, a3; scanf_s("%d%d%d", &a1, &a2, &a3);//改错 printf("a1=%d,a2=%d,a3=%d\n", a1, a2, a3); c1 = getchar();//改错 c2 = getchar();//改错 c3 = getchar();//改错 scanf_s("%c%c%c", &c1, &c2, &c3); printf("c1=%c,c2=%c,c3=%c\n", c1, c2, c3); scanf_s("%lf%lf", &x,&y);//改错 printf("x=%f,y=%lf\n",x,y); return 0; }
实验2:如上图
#include <stdio.h> #include <math.h> int main() { double x, ans; while (scanf_s("%lf", &x) != EOF) { ans = pow(x, 365); printf("%.2f的365次方: %.2f\n", x, ans); printf("\n"); } return 0; }
#include <stdio.h> #include <math.h> int main() { double c, ans; while (scanf_s("%lf", &c) !=EOF) { ans = 9*c/5+32; printf("摄氏度c=%.2f时,华氏度f=: %.2f\n", c, ans); printf("\n"); } return 0; }
实验3:如上图
#include <stdio.h> #include <math.h> int main() { char c; while (scanf_s("%c", &c) !=EOF) { switch(c) { case 'r':printf("%s", "stop!\n"); break; case'g':printf("%s", "go go go\n"); break; case'y':printf("%s", "wait\n"); break; default:printf("%s", "something must be wrong\n"); break; } } return 0; }
实验4:如上图
#include <stdio.h> #include <math.h> int main() { int day,gd; day = rand() % 31; printf("%s", "开始了,你有两次机会"); scanf_s("%d", &gd); if (gd < day) { printf("%s", "你猜的日期早了,lucky day还没到呢\n"); printf("%s", "再猜\n"); scanf_s("%d", &gd); } else if (gd > day) { printf("%s", "你猜的日期晚了,lucky day已经过啦\n"); printf("%s", "再猜\n"); scanf_s("%d", &gd); } else { printf("%s", "你猜对啦\n"); } printf("%s", "机会用完了,悄悄告诉你你的luckyday是"); printf("%d", day); return 0; }
实验5:如上图
#include <stdio.h> #include <math.h> int main() { int i, j,s=1; for (i = 1; i <= 9; i++) { for (j = 1; j <= i; j++) { s = i * j; printf("%d*%d=%d ", j, i, s); } printf("\n"); } return 0; }
实验6:如上图
#include<stdio.h> int main() { int n; printf("input n:"); scanf_s("%d", &n); for (int i = n; i > 0; i--) { for (int j = 0; j < n - i; j++) { printf("\t"); } for (int k = 0; k < 2 * i - 1; k++) { printf(" O \t"); } printf("\n"); for (int j = 0; j < n - i; j++) { printf("\t"); } for (int k = 0; k < 2 * i - 1; k++) { printf("<H>\t"); } printf("\n"); for (int j = 0; j < n - i; j++) { printf("\t"); } for (int k = 0; k < 2 * i - 1; k++) { printf("I I\t"); } printf("\n"); } return 0; }
实验7: 如上图
标签:include,int,scanf,实验,printf,main,day From: https://www.cnblogs.com/zcyy123/p/17224419.html