首页 > 其他分享 >实验二

实验二

时间:2023-10-17 12:33:26浏览次数:31  
标签:Code int -- while 实验 printf include

task1.c

 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 } 
View Code

task2.c

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

task3.c

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

 

task4.c

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

 

 task5.c

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

task6.c

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

 

标签:Code,int,--,while,实验,printf,include
From: https://www.cnblogs.com/zyqJ/p/17767786.html

相关文章

  • 实验2
    task11#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#defineN55#defineN13746#defineN24657intmain()8{9intnumber;10inti;11srand(time(0));//以当前系统时间作为随机种子12for(i=0;i<N;++i){......
  • 实验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......
  • 第二次实验
    任务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; printf("......
  • 实验二
    #include<stdio.h>#include<math.h>intmain(){intn,a,up,down,i=1;doubles;while(scanf("%d%d",&n,&a)==2){while(i<=n){up=i;down+=a*pow(10,i-1);s+=up*1.......
  • 实验二
    task1code1#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#defineN55#defineN13746#defineN24657intmain()8{9intnumber;10inti;11srand(time(0));//以当前系统时间作为随机种子12for(i=......
  • 实验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(......