首页 > 其他分享 >实验二

实验二

时间:2023-10-16 23:35:00浏览次数:37  
标签:main code int 实验 printf include day

task1 code

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4 #define N 5
 5 #define N1 374
 6 #define N2 465
 7 int main()
 8 {
 9     int number;
10     int i;
11     srand(time(0)); // 以当前系统时间作为随机种子
12     for (i = 0; i < N; ++i) {
13         number = rand() % (N2 - N1 + 1) + N1;//
14         printf("202383290376%04d\n", number);
15     }
16     return 0;
17 }

task1 result

Q1:生成一个374-465之间的随机数。

Q2:在学号后面随机生成随机数

task2 code

 1 int main() {
 2     char ch;
 3 
 4     while (scanf("%c", &ch) != EOF) {
 5         if (ch >= 'a' && ch <= 'z') {
 6             if (ch == 'r')
 7                 printf("stop!\n");
 8             else if (ch == 'g')
 9                 printf("go go go\n");
10             else if (ch == 'y')
11                 printf("wait a minute\n");
12             else
13                 printf("something must be wrong\n");
14         }
15     }
16 
17     return 0;
18 }

task2 result

task3 code

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #define F_DAY 1
 4 #define L_DAY 30
 5 int main() {
 6     int day;
 7     int i;
 8     int n;
 9 
10     srand(time(0));
11     day = rand() % (L_DAY - F_DAY + 1) + F_DAY;
12     printf("猜猜2023年11月哪一天会是你的lucky day\n");
13     printf("开始喽,你有三次机会,猜吧(1~30): \n");
14     for (i = 0; i < 3; i++) {
15         scanf("%d", &n);
16         if (n < day) {
17             printf("猜早了\n再猜(1~30): \n");
18         }
19         else if (n == day) {
20             printf("猜中了!\n");
21             break;
22         }
23         else {
24             printf("猜晚了\n再猜(1~30): \n");
25         }
26     }
27     printf("次数用完啦,你的lucky day是%d", day);
28 
29     return 0;
30 }

task3 result

 task4 code

 1 #include<stdio.h>
 2 int main() {
 3     int n, a;
 4     double s = 0;
 5     double i;
 6 
 7     while (scanf("%d%d", &n, &a) != EOF) {
 8         int j = 1;
 9         double sum = 0;
10         for (i = 1; i <= n; i++) {
11             s = i / (a * j);
12             sum += s;
13             j = j * 10 + 1;
14         }
15         printf("n = %d, a = %d, s = %lf\n", n, a, sum);
16     }
17 
18     return 0;
19 }

task4 result

task5 code

 1 #include<stdio.h>
 2 int main() {
 3     int l, c;
 4 
 5     for (l = 1; l <= 9; l++) {
 6         for (c = 1; c <= l; c++) {
 7             printf("%d*%d = %2d ", l, c, l * c);
 8         }
 9         printf("\n");
10     }
11     return 0;
12 }

task5 result

task6 code

 

 1 #include<stdio.h>
 2 int main() {
 3     int n, i, t = 0, j = 0;
 4 
 5     printf("input n: ");
 6     scanf("%d", &n);
 7 
 8     for (; n > 0; n--) {
 9 
10         for (t = 0; t < j; t++) {
11             printf("\t");
12         }
13 
14         for (i = 1; i <= 2 * n - 1; i++) {
15             printf("\t 0 ");
16         }
17         printf("\n");
18 
19         for (t = 0; t < j; t++) {
20             printf("\t");
21         }
22 
23         for (i = 1; i <= 2 * n - 1; i++) {
24             printf("\t<H>");
25         }
26         printf("\n");
27 
28         for (t = 0; t < j; t++) {
29             printf("\t");
30         }
31         
32         for (i = 1; i <= 2 * n - 1; i++) {
33             printf("\tI I");
34         }
35         printf("\n");
36         
37         j += 1;
38     }
39 
40     return 0;
41 }

task6 result

 

标签:main,code,int,实验,printf,include,day
From: https://www.cnblogs.com/nuist0415/p/17767910.html

相关文章

  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1347#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%(N2-N1+1)+N1;......
  • 实验二
    实验二任务一代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain(){10intnumber;11inti;12srand(time(0));1314for(i=1;i<......
  • 实验二
    任务一t.h1#ifndefT_H2#defineT_H3#include<iostream>4#include<string>5usingnamespacestd;6classT7{8public:9T(intx=0,inty=0);10T(constT&t);11T(T&&t);12~T();13voidset_m1......
  • 实验二
    1,源代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));//以当前系统时间作为随机种子for(i=0;i<N;++i){number=rand()%(N2-N1+1)+N1;......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));//以当前系统时间作为随机种子for(i=0;i<N;++i){number=rand()%(N2-N1+1)+N1;printf(......
  • 实验2
    task1问题一:line17作用:限制随机数范围在374~465之间问题二:程序功能:随时间变化,随机生成在202383290376374~202383290376465之间的数task21#include<stdio.h>2intmain(){3chara;4while(1){5a=getchar();6getchar();7if(a==EOF){8......
  • 实验1 类和对象_基础编程
    实验任务11.代码:1#include<iostream>2#include<string>3#include<vector>4#include<array>567//函数模板8//对满足特定条件的序列类型T对象,使用范围for输出9template<typenameT>10voidoutput1(constT&obj){11for(autoi:obj)......
  • 实验2
    实验2.1实验2.1代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=1;i<N;++i){number=rand()%(N2-N1+1)+......
  • 实验二
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%(N2-N1+1)+N1;//计算num的值printf("......
  • 实验2
    task1代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain(){10intnumber,i;1112srand(time(0));1314for(i=0;i<N;++i......