首页 > 其他分享 >实验二

实验二

时间:2023-10-22 17:12:23浏览次数:27  
标签:11 10 main int 实验 printf include

实验1

代码

 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 {
11     int number;
12     int i;
13     srand( time(0) ); // 以当前系统时间作为随机种子
14 
15     for(i = 0; i < N; ++i) {
16         number = rand()%(N2 - N1 + 1) + N1;
17         printf("202383290376%04d\n", number);
18     }
19     return 0;
20 }

截图

 问题1:生成(N2-N1+1)到N1间的随机一个数

问题2:生成一个一定范围的随机数

实验2

代码

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

 

截图

 

实验3

代码

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4  
 5 int main()
 6  {
 7     srand(time(0));
 8     int data= rand()%30+1;
 9        int n=3,a;
10        printf("猜猜2023年11月哪一天是你的lucky day"); 
11     do
12      {
13          scanf("%d",&a);
14         n--;
15         if(a>data) 
16             printf(" 你猜的日期晚了,你的lucky day已经过了\n"); 
17          else if(a<data)
18             printf("你猜的日期早了,你的lucky day还没到\n");
19          }while(a!=data&&n>0);
20          if(a==data) 
21         printf("哇猜中了:-)\n");
22          else if(n==0)    
23             printf("你的lucky day是%d",data) ;
24      
25      system ("pause");
26      
27      
28      return 0;
29  }
30  

截图

 

 实验4

代码

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

截图

 实验5

代码

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main()
 5 {
 6     int line, first,i;
 7       line = 1;
 8        first = 1;
 9    
10 for (line = 1;line <= 9;line++)
11 {
12      for (first = 1;first <= line;first++)
13 {
14      i = first*line;
15          printf("%dx%d = %d ",first,line,i);
16 }
17        printf("\n");
18 }
19   
20       system("pause");
21       
22     return 0;
23  }

截图

 实验6

代码

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main()
 5 {
 6     printf("input n:"); 
 7     int n, i, m;
 8     i = 0;
 9        m = 0;
10    
11        scanf("%d",&n);
12   
13       while (n > 0)
14   {
15       for (i = 0;i < m;i++)
16       {
17           printf("      ");
18       }
19      
20      for (i = 0;i <= 2*(n-1);i++)
21      {
22          printf(" o    ");
23      }
24      
25      printf("\n");
26     
27     for (i = 0;i < m;i++)
28      {
29           printf("      ");
30       }
31      
32      for (i = 0;i <= 2*(n-1);i++)
33      {
34          printf("<H>   ");
35      }
36      
37      printf("\n");
38     
39      for (i = 0;i < m;i++)
40       {
41           printf("      ");
42      }     
43      for (i = 0;i <= 2*(n-1);i++)
44      {
45          printf("I I   ");
46      }
47      printf("\n");
48      
49      n--;
50      m++;
51   }
52   
53   system("pause");
54   return 0;
55  }
56  

 

截图

 

 

标签:11,10,main,int,实验,printf,include
From: https://www.cnblogs.com/z00z/p/17780704.html

相关文章

  • 实验二 类和对象
    task1.cpp方式一t.h#ifndefT_H#defineT_H#include<iostream>#include<string>usingnamespacestd;classT{public:T(intx=0,inty=0);T(constT&t);T(T&&t);~T();voidset_m1(intx);intget_m1()const;......
  • 实验二 类和对象
    实验任务1task1.cpp源码t.h:1#ifndefT_H2#defineT_H34#include<iostream>5#include<string>67usingnamespacestd;89//类T的声明10classT{11public:12T(intx=0,inty=0);//带有默认形值的构造函数13T(constT&t)......
  • 实验2
     ......
  • 实验二
    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......
  • 实验二-类和对象_基础编程2
    task1t.hpp1#pragmaonce2#include<iostream>3#include<string>4usingnamespacestd;56classT{7public:8T(intx=0,inty=0);9T(constT&t);10T(T&&t);11~T();12voidset_m1(intx);13intget......
  • 实验2
    实验任务1代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain()10{11intnumber;12inti;1314srand(time(0));1516for(i=......
  • 实验课二
    一、task1    1,源代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain()10{11intnumber;12inti;13srand(time(0));1415for(i......
  • 实验2 类和对象
    实验任务3Complex.hpp#pragmaonce#include<iostream>#include<cmath>classComplex{public:Complex(doubler=0,doublei=0){real=r;imag=i;}Complex(constComplex&x){real=x.real......
  • 实验2
    实验任务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......
  • 实验2 C语言分支与循环基础应用编程
    实验任务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;pr......