首页 > 其他分享 >实验2

实验2

时间:2024-04-14 22:34:19浏览次数:25  
标签:include int scanf break 实验 printf main

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 5
int main(){
    int number;
    int i;
    srand(time(0));
    for(i=0;i<N;++i){
        number=rand()%65+1;//生成一个1-65之间的随机数
        printf("20238331%04d\n",number);
    }
    system("pause");
return 0;
}

任务二

#include<stdio.h>
#include<stdlib.h>
int main(){
    char n;
    while(scanf("%c",&n)!=EOF)
    {
        switch(n)
        {case'r':printf("stop!\n");break;
        case'g':printf("go go go\n");break;
        case'y':printf("wait a minute\n");break;
        default:printf("something must be wrong\n"); break; } 
        getchar();
    }
    system("pause");
return 0;}

任务三

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 3
int main()
{
int lucky,day,i;
srand( time(0) ); 

lucky= rand()%31 + 1;
printf("猜猜2024年5月哪一天会是你的lucky day\n");
printf("开始喽,你有三次机会,猜吧(1~31)\n");
for(i = 0; i < N; ++i) {
    scanf("%d",&day);
    {if(day<lucky) 
{printf("你猜的日期早了,你的lucky day还没到呢\n"); }
    else if(day>lucky)
{printf("你猜的日期晚了,你的lucky day在前面哦\n");}
    else 
{printf("哇,猜中了:-)");
break;
}
    }
{if(i<N-1)
printf("再猜(1~31)\n");
}
}

printf("次数用完啦。偷偷告诉你,五月你的lucky day是%d号",lucky);
system("pause");
return 0;
}

任务四

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
    int i,n,a;
    printf("输入n和a:");
    while(scanf("%d%d",&n,&a)!=EOF){
        double s=0,m=0,j;
    for(i=1;i<=n;i++){
    m=m*10+a;
    j=i/m;
    s=s+j;
    }
    printf("n=%d,a=%d,s=%lf",n,a,s);}
    system ("pause");
return 0;}

任务五

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
    int i,j,k;
    for(i=1;i<=9;i++)
    {  for(j=1;j<=i;j++)
         { k=i*j;
    printf("%d×%d=%d\t",j,i,k);}
    printf("\n");
    
    }
    
    system ("pause");
return 0;}

任务六

#include<stdio.h> 
#include<stdlib.h> 
int main() 
{
int n,a=0; 
printf("input n:"); 
scanf("%d",&n);
for(;n>=1;n=n-1) 
{
for(int m=1;m<=a;m=m+1) 
{
printf("\t"); 
} 
for(int i=1;i<=2*n-1;i=i+1) 
{
printf(" O\t"); 
}
printf("\n"); 
for(int m=1;m<=a;m=m+1) 
{
printf("\t"); }
for(int j=1;j<=2*n-1;j=j+1) 
{
printf("<H>\t");} 
printf("\n"); 
for(int m=1;m<=a;m=m+1) 
{printf("\t");} 
for(int b=1;b<=2*n-1;b=b+1) 
{printf("I I\t"); }
printf("\n"); 
a=a+1; 
} 
system("pause"); 
return 0;
}

 

标签:include,int,scanf,break,实验,printf,main
From: https://www.cnblogs.com/xxtt778725/p/18134831

相关文章

  • 第二次实验
    练习一:line15是在1~65的范围内随机取数这个程序生成202383310001~202383310065之间的学号练习二:include<stdio.h>intmain(){charcolor;while(scanf("%c",&color)!=EOF){ switch(color){ case'r':printf("stop!\n"); break; case'g�......
  • 实验二
    项目1代码`#include<stdio.h>include<stdlib.h>include<time.h>defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",number);}sys......
  • 实验二
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){ intnumber; inti; srand(time(0)); for(i=0;i<N;i++){ number=rand()%65+1; printf("20238331%04d\n",number); } return0;}#i......
  • 实验2 C语言分支与循环基础应用编程
    任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;//生成一个1-65之间的随机数printf("20238331%04d\n&q......
  • 实验二
    任务一include<stdio.h>include<stdlib.h>include<time.h>defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){ number=rand()%65+1; printf("20238331%04d\n",number);}return0;}问题一:在一到六十五之......
  • 实验2
    实验一#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",number);......
  • 实验2
    `#include<stdio.h>include<stdlib.h>include<time.h>defineN5intmain(){intnumber;inti;srand(time(0));//以当前系统时间作为随机种子for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",numbe......
  • 实验2-
    task1.c点击查看代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));//以当前系统时间作为随机种子for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n"......
  • 实验2
    实验2.1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n",number......
  • 实验2
    task1点击查看代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));//以当前系统时间作为随机种子for(i=0;i<N;++i){number=rand()%65+1;printf("20238331%04d\n"......