首页 > 其他分享 >实验2

实验2

时间:2023-10-19 23:56:58浏览次数:33  
标签:11 include int number 实验 printf main

task1.c

#include <stdio.h>
#include <stdlib.h>
#include <time.h>


#define N 5
#define N1 374
#define N2 465

int main(){
    
    int number;
    int i;
    
    srand(time(0) );
    
    for (i =0; i< N; i++){
        number = rand()%(N2 - N1 + 1) + N1;
        printf("202383290376%04d\n", number);
    }
    
    return 0;
} 

 

 

实验任务2

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

运行结果

 

实验任务3

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(){
int number;
srand (time(0));
number = rand()%30 +1;
printf ("猜猜2023年11月哪一天是你的lucky day\n");
printf("开始喽 ,你有三次机会, 猜吧(1~30):");
int a ,i;

i =1;
while(i<=3){
scanf("%d", &a);
if (a<number){
printf("你猜的日期的日期早了 ,你的 lucky day 还没到呢\n再猜:");}
else if(a>number){
printf ("你猜的日期晚了 , 你的lucky day已经过了\n再猜:");
}
else if(a == number )
{printf("哇,猜中了:-)");
return 0;}
i++;
}

printf ("次数用完了 ,偷偷告诉你:11月,你的lucky day 是:%d",number);
return 0;

}

 

实验任务4

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

运行结果

实验任务5

 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 return 0;
13 
14 }

运行结果

实验任务6

 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 }

运行结果

 

标签:11,include,int,number,实验,printf,main
From: https://www.cnblogs.com/fz1003yy/p/17767924.html

相关文章

  • 实验二
    实验任务11#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13747#defineN246589intmain()10{11intnumber;12inti;1314srand(time(0));1516for(i=0;i&......
  • 实验1
    任务1//标准库string,vector,array基础用法#include<iostream>#include<string>#include<vector>#include<array>//函数模板//对满足特定条件的序列类型T对象,使用范围for输出template<typenameT>voidoutput1(constT&obj){for(autoi:obj)st......
  • 实验1 类和对象
    实验任务一:1#include<iostream>2#include<string>3#include<vector>4#include<array>5template<typenameT>6voidoutput1(constT&obj)7{8for(autoi:obj)9std::cout<<i<<",";......
  • 实验一
    任务一点击查看代码#include<iostream>#include<string>#include<vector>#include<array>template<typenameT>voidoutput1(constT&obj){for(autoi:obj)std::cout<<i<<",";std::cout<<&qu......
  • 实验一 类与对象
    Task1:#include<iostream>#include<string>#include<vector>#include<array>template<typenameT>voidoutput1(constT&obj){for(autoi:obj)std::cout<<"i"<<",";std::cout<<......
  • 实验1_OOP_22物联网1班_张文瑞
    1.实验任务1:  实验源代码:1//标准库string,vector,array基础用法2#include<iostream>3#include<string>4#include<vector>5#include<array>6//函数模板7//对满足特定条件的序列类型T对象,使用范围for输出8template<typenameT>9voidoutpu......
  • 实验1 类与对象
    实验任务1源代码:1#include<iostream>2#include<string>3#include<vector>4#include<array>567template<typenameT>8voidoutput1(constT&obj){9for(autoi:obj)10std::cout<<......
  • 实验二.
     test1#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.实验任务一task1源代码: 1//标准库string,vector,array基础用法23#include<iostream>4#include<string>5#include<vector>6#include<array>78//函数模板9//对满足特定条件的序列类型T对象,使用范围for输出10template<typename......