首页 > 其他分享 >实验2

实验2

时间:2024-04-14 23:24:19浏览次数:23  
标签:guess int lucky 实验 printf include day

任务一:
`#include<stdio.h>

include<stdlib.h>

include<time.h>

define N 5

int mian(){
int number;
int i;
srand(time(0));
for(i=0;i<N;++i){
number = rand()%65+1;
printf("20238331%04d\n",number);

}
return 0;
}
`
问题1:生成1到65的随机数
问题2:生成随机学号

任务二:

include<stdio.h>

include<stdlib.h>

int main()
{
char color;
while(1)
{
while(getchar()!='\n'){
continue;
}

scanf("%c",&color);
switch(color){

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;
}
}
system("pause");
return 0;

}

任务三:
`#include <stdio.h>

include <stdlib.h>

include <time.h>

int main() {

srand((int) time(0));  
int lucky_day = rand() % 31+1;  

int guess_day;
printf("猜猜2024年5月哪一天会是你的lucky day?\n");

for (int i = 1; i <= 3; i++) {  
    
    printf("请输入你猜测的日期(1-31):");  
    scanf("%d", &guess_day);  
    
    if (guess_day == lucky_day) {  
        printf("恭喜!你猜中了,5月%d号是你的lucky day!\n", lucky_day);  
        break;  
    } else {  
       
        if (lucky_day > guess_day) {  
            printf("你猜的日期早了,还有%d天才是你的lucky day。再猜一次吧!\n", lucky_day - guess_day );  
        } else {  
            printf("你猜的日期晚了,还有%d天才是你的lucky day。再猜一次吧!\n", guess_day - lucky_day );  
        }  

	}
	if (i==3 && guess_day != lucky_day){
	printf("很遗憾,你没有在三次内猜中,5月%d号是你的lucky_day\n",lucky_day);
	}
} 

system ("pause");
return 0;  

}

`

任务四:
`#include <stdio.h>

include <stdlib.h>

include <math.h>

int main() {

int b=0;
int n,a;  
while(scanf("%d%d", &n, &a)==2){;  
double s = 0.0;  
for (int i = 1; i <= n; i++) { 
	b = b*10+a;
    s += 1.0*i/b;
}  
printf("S = %.10lf\n", s);  
system("pause");}
return 0;  

}

`

任务五:
`#include <stdio.h>

include <stdlib.h>

int main() {
int i,j;
for (int i = 1; i <= 9; i++) {

    for (int j = 1; j <= i; j++)  
        printf("%d×%d=%d\t", i, j, i * j);  
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<=2n-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("\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;
}`

标签:guess,int,lucky,实验,printf,include,day
From: https://www.cnblogs.com/jiuzhuang/p/18121189

相关文章

  • 原型设计实验
    原型设计工具比较分析:墨刀:适用领域:墨刀适用于快速原型设计和交互设计,特别适合移动应用和Web应用的设计。优点:界面简洁清晰,易于上手,适合初学者和团队合作。支持多种交互模式,如链接、滑动、弹出框等,可以较好地模拟用户操作流程。支持团队协作,可以多人同时编辑同一项目,方便团队......
  • 实验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; printf("20238331%04d\n",number); } return0;}......
  • 实验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;//控制随机数的范围从1~66printf("2023......
  • 实验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("2023833%04d\n",number); } ret......
  • 实验二
    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("202......
  • 实验二。
    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 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",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;//生成一个1-65之间的随机数printf("20238331%04d\n",......
  • 第二次实验
    练习一: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......