首页 > 其他分享 >实验2

实验2

时间:2023-03-19 15:56:42浏览次数:32  
标签:include int scanf 12 实验 printf main

实验任务1

 1 #include <stdio.h.>
 2 #include <stdlib.h>
 3 #include <time.h>
 4 
 5 #define N 5
 6 #define R1 586
 7 #define R2 701
 8 
 9 int main()
10 {
11     int number;
12     int i;
13 
14     srand(time(0));
15 
16     for (i = 0; i < N; ++i)
17 
18     {
19         number = rand() % (R2 - R1 + 1) + R1;
20         printf("20228330%04d\n", number);
21 
22         
23     }
24     return 0;
25 
26 }

 

问题1:生成586-701的随机整数

问题2:利用系统时间为随机种子,rand()函数生成586-701的随机整数,打印出尾号586-701的五个学号。

 

实验任务2

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     double x, y;
 6     char c1, c2, c3;
 7     int a1, a2, a3;
 8 
 9     scanf("%d%d%d",&a1 ,&a2,&a3);
10     printf("a1=%d,a2=%d,a3=%d\n", a1, a2, a3);
11     scanf(" %c %c %c", &c1, &c2, &c3);
12     printf("c1=%c,c2=%c,c3=%c\n", c1, c2, c3);
13     scanf("%lf %lf", &x, &y);
14     printf("x=%f,y=%f\n" ,x, y);
15 
16     return 0;
17 
18 }

 

 

实验任务3

task3_1.c

 1 #include <stdio.h>
 2 #include <math.h>
 3 
 4 int main() {
 5 
 6     double x, ans;
 7 
 8     scanf_s("%lf",&x);
 9 
10     ans = pow(x, 365);
11     printf("%.2f的365次方:%.2f\n",x,ans);
12 
13     return 0;
14 
15 }

 

 

task3_2.c

 1 #include <stdio.h>
 2 #include <math.h>
 3 
 4 int main() {
 5 
 6     double x, ans;
 7     while (scanf_s("%lf", &x) != EOF)    
 8     {
 9         ans = pow(x, 365);
10         printf("%.2f的365次方:%.2f\n", x, ans);
11         printf("\n");
12 
13     }
14     return 0;
15     
16 }

 

task3_3.c

 1 #include <stdio.h>
 2 int main() {
 3 
 4     double c,f;
 5     while (scanf_s("%lf", &c) != EOF) {
 6         f = 9 / 5 * c + 32;
 7         printf("摄氏度c=%0.2lf,", c);
 8         printf("华氏度f=%0.2lf\n", f);
 9 
10     }
11     return 0;
12 
13  }

 

 

实验任务4

 1 #include <stdio.h>
 2 
 3 int main() {
 4 
 5     char sign;
 6     
 7     while (scanf_s("%c", &sign) != EOF) {
 8         getchar();
 9 
10         if (sign == 'r')
11         {
12             printf("stop!\n");
13 
14         }
15         else if (sign == 'g') {
16             printf("go go go\n");
17         }
18         else if (sign == 'y')
19         {
20             printf("wait a minute\n");
21 
22         }
23         else
24         {
25             printf("something must be wrong...\n");
26         }
27     }
28     return 0;
29 }

 

 

实验任务5

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4 int main()
 5 {
 6     int lucky_day, i=1, j;
 7     printf("猜猜2023年4月哪一天会是你的lucky day\n");
 8     printf("开始咯,你有三次机会,猜吧(1-30):");
 9     scanf_s("%d", &j);
10 
11     srand(time(0));
12     lucky_day = rand() % (30 - 1 + 1) + 1;
13 
14     while(i<=3)
15     {
16         if (j == lucky_day)
17         {
18             printf("哇猜中了");
19             i = 5;
20         }
21         else
22 
23         {   i++;
24             if (j < lucky_day)
25             {
26                 if (i == 4)
27                 {
28                     printf("次数用完啦,偷偷告诉你:4月,你的lucky day 是%d", lucky_day);
29                     exit(0);
30                 }
31                 else
32                 {
33                     printf("你猜的日期早了,你的lucky day还没到呢\n");
34                     printf("再猜(1-30):");
35                 }
36             
37             }
38             else
39             {
40                 if (i == 4) 
41                 {
42                     printf("次数用完啦,偷偷告诉你:4月,你的lucky day 是%d", lucky_day);
43                     exit(0);
44                 }
45                 else
46                 {
47                     printf("你猜的日期晚了,你的lucky day已经过啦\n");
48                     printf("再猜(1-30):");
49                 }
50             }
51             scanf_s("%d", &j);
52             
53         }
54         
55     }
56     return 0;
57 }
58     

 

 

 

实验任务6

 

 1 #include <stdio.h>
 2 
 3 int main() 
 4 {
 5     int line, column;
 6 
 7     for (line=1; line <= 9; line++)
 8     {
 9         for (column=1; column<=line; column++)
10         {
11             printf("%dx%d=%d", line, column,line*column);
12             printf("\t");
13         }
14         printf("\n");
15     }
16     
17     return 0;
18 }

 

 

 

实验任务7

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

 

标签:include,int,scanf,12,实验,printf,main
From: https://www.cnblogs.com/shaobky/p/17231424.html

相关文章

  • 实验2
    实验任务1程序源码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验报告1
     ......
  • 实验二
    test1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sran......
  • 实验二
    实验任务一  1:随机生成一个586和701之间的数字 2:随机生成五个最后四位在586和701之间的数字 实验任务二#include<stdio.h>intmain(){doublex,y;......
  • 实验2
    实验任务1源代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • pta python实验1-3
    7-1HelloWorld这是学习每种程序设计语言的第一个实例。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬输出Hell......
  • 实验2
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;srand......
  • 实验2
    实验任务1:代码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验二
    实验任务一源代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • SYNU PTA C++ 第三章实验题
    题目详细内容见PTA,仅提供答案参考。7-7冒泡1#include<iostream>2usingnamespacestd;34voidmerge(int*arr,intleft,intmid,intright)5{6......