首页 > 其他分享 >实验二

实验二

时间:2023-03-17 23:44:26浏览次数:30  
标签:main int scanf 源码 实验 printf include

1、程序源码

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

#define N 5
#define R1 586
#define R2 701

int main(){
	int number;
	int i;

	srand(time(0));
	for(i = 0;i<N;++i)
	{
		number = rand()%(R2-R1+1)+R1;
		printf("20228330%04d\n",number);
	}

	system("pause");
	return 0;
}

  

(1)生成一个在R1到R2之间的随机数

(2)随机抽取五个学号

2、程序源码

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

int main(){
double x, y;
char c1, c2, c3;
int a1, a2, a3;
scanf("%d%d%d", &a1,&a2,&a3);//加入地址符//
printf("a1 = %d, a2 = %d, a3 = %d\n", a1,a2,a3);//分开后加入getchar()//
getchar();
scanf("%c",&c1);
getchar();
scanf("%c",&c2);
getchar();
scanf("%c",&c3);
getchar();
printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);//分开后加入getchar(),%f改%lf//
scanf("%lf", &x);
getchar();
scanf("%lf",  &y);
printf("x = %f, y = %lf\n",x, y);
	
		system("pause");
	return 0;
}

  

实验截图

 

3.2、程序源码

 

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

int main(){
	double x,ans;
	while(scanf("%lf",&x)!=EOF)
	{
	ans=pow(x,365);
	printf("%.2f的365次方:%.2f\n",x,ans);
	printf("\n");
	}
		system("pause");
	return 0;
}

  

实验截图

 

3.3、程序源码

 

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

int main(){
	double c,f;
	while(scanf("%lf",&c)!=EOF)
	{
	f=((9*c)/5+32);
	printf("摄氏度c=%.2f时,华氏度f=%.2f\n",c,f);
	printf("\n");
	}
		system("pause");
	return 0;
}

  

实验截图

 

4、程序源码

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

int main(){
	char c;
	printf("输入交通信号灯的颜色r,g或y\n");
	while(scanf("%c",&c)!=EOF)
	{switch(c)
	{
	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;
	}
	scanf("%c",&c);
	}
		system("pause");
	return 0;
}

  

实验截图

 

5、程序源码

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

int main(){
	int number,day,n;
	int i=1;
	printf("猜猜你的lucky day\n开始喽你有三次机会,猜吧(1~30)\n");
	srand(time(0));
	number = rand()%(30+1);
	
	while(i<4)
	{scanf("%d",&day);
	getchar();
	if(day==number)
	     printf("哇,猜中了\n");
	else
		{if(number<day)
			printf("你猜的日期晚了,lucky day已经过了\n");
		else
			printf("你猜的日期早了,lucky day还没到哦\n");}
	i++;
	if(day==number)
	    break;
	else
		i;
	if(i==4)
		printf("%d",number);
	else
	i;
	}
	
		system("pause");
	return 0;
}

  

实验截图

 

6、程序源码

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

int main(){
	int i,j;
	i=1;
	while(i<10)
	{i++;}
	i=1;
	while(i<10)
	{printf("\n");
	j=1;
	while(j<=i)
	{printf("%dx%d=%d\t",i,j,i*j);
	j++;}
	i++;}
	i++;
	system("pause");
	return 0;
}

  

实验截图

 

7、

实验原理

当输入为n时: 第i行,需要打印(2(n-i)-1)个字符小人 第i行,前面需要打印(i-1)个空白

程序源码

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


int main(){
	int n,m,a,i;
	i=0,m=1,a=1;
	scanf("%d",&n);
	while(i<3*n)
	{m=1;
	a=1;
	if(i%3==1)
	{
		while(m<=(i-1)/3)
		{printf(" \t");
         m++;}
        while(a<2*(n-(i-1)/3))
	    {printf("<H>\t");
		a++;}}
	else
	{if(i%3==2)
      {
	     while(m<=(i-2)/3)
		{printf(" \t");
         m++;}
        while(a<2*(n-(i-2)/3))
	    {printf("I I\t");
		a++;}}
		else
	{if(i%3==0)
      {
	     while(m<=(i/3))
		{printf(" \t");
         m++;}
        while(a<2*(n-i/3))
	    {printf(" o\t");
		a++;}}
	else
		i;
	}}
	printf("\n");
	i++;}
		system("pause");

	return 0;
}

  

实验截图

 

标签:main,int,scanf,源码,实验,printf,include
From: https://www.cnblogs.com/dmdshuangxu/p/17228739.html

相关文章

  • 实验2
     任务一#include<stdio.h>#include<math.h>#include<stdlib.h>intmain(){ doublex,ans; while(scanf("%if",&x)!=EOF) { printf("202283300......
  • 实验2 c语言输入输出和控制语句应用编程
    TEST 1源代码:#include<stdlib.h>#include<stdio.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){  intnumber;  inti;  sran......
  • 实验2
    #include<stdio.h>//task2.1#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;s......
  • 实验2 C语言输入输出和控制语句应用编程
    一.实验结论1.实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;......
  • 保龄球比赛计分程序实验报告
    1.试验目的写一个保龄球比赛计分程序。2.实验过程在写这个程序的过程中,我们犯了很多的错误。这些错误包括代码方面的、逻辑方面的、设计方面的以及需求方面的。在写这个......
  • 实验2
    实验任务1实验代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){ intnumber; inti; sra......
  • 实验2
    实验任务1程序代码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验2
    实验二任务1:代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber,i;......
  • 实验2
    实验2task1.实验代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){ intnumber; inti; sra......
  • 实验2
    实验任务一代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#defineN55#defineR15866#defineR27017intmain()8{9......