首页 > 其他分享 >实验二

实验二

时间:2023-10-16 23:33:42浏览次数:43  
标签:截图 include int number 实验 printf main

实验二

任务一代码

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

 

任务一截图

 

 

任务二代码

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

 

任务二截图

 

任务三代码

 1 #include<stdio.h> 
 2 #include<stdlib.h> 
 3 #include<time.h> 
 4 
 5 int main(){
 6     int number,c,i;
 7     srand(time(0)); 
 8     number = rand()%30 + 1;
 9     printf("猜猜2023年11月的哪一天是你的lucky day\n开始咯,你有三次机会,猜猜吧(1~30):");
10     i = 1;
11     while(i <= 3){
12         scanf("%d",&c);
13         if(c > number){
14             printf("你猜的日期晚了,你的lucky day已经过了\n");
15         }
16         else if (c < number){
17             printf("你猜的日期早了,你的lucky day还没到呢\n");
18         }
19         else if(c == number){
20             printf("哇,猜中啦:)");
21             return 0;
22         }    
23         i++;
24     }
25     printf("三次机会已经用光啦!偷偷告诉你,你的幸运日是:11月·%d日",number);
26     
27     
28     
29     
30     
31     
32     return 0;
33 } 

 

任务三截图

 

任务四

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

 正确的

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

 

任务四截图

 

 

 

任务五代码

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

 

任务五截图

 

任务六代码

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

 

任务六截图

 

标签:截图,include,int,number,实验,printf,main
From: https://www.cnblogs.com/kujievan1/p/17767938.html

相关文章

  • 实验二
    任务一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......
  • 实验二 c语言分支与循环基础应用编程
    实验一源代码#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("20238329%04......
  • 实验二
    task1#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+......