试验任务1
task 1.c
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 #define N1 374 #define N2 465 int main() { int number; int i; srand( time(0)); for(i = 0; i < N; ++i){ number = rand()%(N2 - N1 + 1) + N1; printf("202383290376%04d\n", number); } return 0; } //第十七行的作用:生成一个在374到465范围内的随机数 //程序作用:在学号后面随机生成一个四位数,范围在374到465
试验任务2.c
#include <stdio.h> int main() { char c; while(c != EOF) { printf("请输入信号灯的颜色:(r,g,y 红,绿,黄)"); scanf("%c", &c); getchar(); switch (c) { case 'r': printf("stop!\n"); break; case 'g': printf("go go go\n"); break; case 'y': printf ("wate a minute\n"); break; } } return 0; }
试验任务3
#include<stdio.h> #include<stdlib.h> #include<time.h> int main(){ int luckyday = 0; int guess; int chances = 3; srand(time(0)); luckyday = rand() % 30 + 1; printf("猜猜2023年11月哪一天是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1~30):"); while(chances > 0){ scanf("%d",&guess); if (guess == luckyday){ printf("哇,猜中了:-)\n"); break; } else if (guess < luckyday){ printf("你猜的日期早了,你的lucky day还没到呢\n"); } else{ printf("你猜的日期晚了,你的lucky day已经过啦\n"); } chances--; if(chances > 0){ printf("再猜(1~30):"); } else{ printf("次数用完啦。偷偷告诉你:11月,你的lucky day是%d号\n",luckyday); } } return 0; }
试验任务4
#include <stdio.h> int main(void) { int n, a, b, c; double x, s; while(1 != EOF){ printf("\n请输入正整数n, a\n"); scanf("%d",&n); scanf("%d",&a); for(b=1,c=0; b <= n;b++){ c = c*10 + a; x = 1.0 *b/c; s += 1.0 *x; } printf("n = %d, a = %d,s = %f",n,a,s); } return 0; }
试验任务5
#include <stdio.h> int main(void) { int a, b, c, n = 9; for(a = 1;a < n+1;a++){ for(b = 1;b < a+1;b++){ c = b*a; printf("%d*%d = %2d ",b,a,c); } printf("\n"); } }
试验任务6
#include <stdio.h> int main(void) { int n, a, b, c, d, e, x,t; printf("input e:"); scanf("%d",&e); n=(e-1)*2+1; x = n; for(b=1,c=0,t=0;b<=x;b++,c +=2,t+=4){ for(int j = 1;j <= b-1+t;j++) printf(" "); for(a=1;a<=n-c;a++){ printf(" o "); } printf("\n"); for(int j = 1;j <= b-1+t;j++) printf(" "); for(a=1;a<=n-c;a++){ printf("<H> "); } printf("\n"); for(int j = 1;j <= b-1+t;j++) printf(" "); for(a=1;a<=n-c;a++){ printf("I I "); } printf("\n"); } return 0; }
标签:main,int,scanf,编程,分枝,luckyday,C语言,printf,include From: https://www.cnblogs.com/NJ-1230/p/17771353.html