首页 > 其他分享 >实验2

实验2

时间:2023-10-17 11:48:48浏览次数:32  
标签:Code int number 实验 printf include define

task1

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

1.在374~465之间随机数字

2.随机抽取学生学号

task2

 1 #include<stdio.h>
 2 int main(){
 3     char n;
 4     while(scanf("%c",&n)!=EOF){
 5         getchar();
 6         switch(n){
 7         case 'r' :printf("stop!\n");break;
 8         case 'y' :printf("wait a minute\n");break;
 9         case 'g' :printf("go go go\n");break;
10         default :printf("something must be wrong...\n");break;
11         }
12     }
13     return 0;
14 } 
View Code

task3

 1 #include<stdio.h>
 2 #include<time.h>
 3 #include<stdlib.h>
 4 #define N 4
 5 #define N1 1
 6 #define N2 30
 7 int main(){
 8     int number,count=0,n;
 9     printf("猜猜2023年11月哪天会是你的lucky day吧~\n");
10     printf("开始吧,你有三次机会~(1~30)\n");
11     srand(time(0) );
12     number=rand()%(N2-N1+1)+N1;
13     if(n==number)
14         printf("哇,猜中了!");
15     while(scanf("%d",&n)!=EOF){
16         if(n<number)
17             printf("你的日期猜早了,你的lucky day还没到呢\n再猜:");
18         if(n>number)
19             printf("你的日期猜晚了,你的lucky day已经过了\n再猜:");
20         ++count;
21         if(count==3){
22             printf("次数用完啦,答案是:%d",number);break;
23         }
24     }
25     return 0;
26 }
View Code

task4

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

task5

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

task6

 1 #include<stdio.h>
 2 int main(){
 3     int n,a,b,s,m;
 4     printf("请输入n:");
 5     scanf("%d",&n);
 6     m=n;
 7     for(;n>0;n--){
 8         for(s=n;s<m;s++)
 9             printf("\t");
10         for(a=2*n-1;a>0;a--){
11             printf(" O \t");
12             }
13         printf("\n");
14         for(s=n;s<m;s++)
15             printf("\t");
16         for(a=2*n-1;a>0;a--){
17             printf("<H>\t");
18             }
19         printf("\n");
20         for(s=n;s<m;s++)
21             printf("\t");
22         for(a=2*n-1;a>0;a--){
23             printf("I I\t");
24             }
25         printf("\n");
26     }
27     return 0;
28 }
View Code

 

标签:Code,int,number,实验,printf,include,define
From: https://www.cnblogs.com/zjl-love-wsx/p/17769308.html

相关文章

  • 实验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(......
  • 实验2
    task1问题一:line17作用:限制随机数范围在374~465之间问题二:程序功能:随时间变化,随机生成在202383290376374~202383290376465之间的数task21#include<stdio.h>2intmain(){3chara;4while(1){5a=getchar();6getchar();7if(a==EOF){8......