首页 > 其他分享 >实验2

实验2

时间:2023-03-17 16:56:08浏览次数:26  
标签:main int ++ 实验 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); 
	} 
	
	return 0;
}

实验结论

回答问题

问题一:生成一个586~701之间的随机数
问题二:生成五个202283300586~202283300701之间的学号

实验任务2

实验代码

#include <stdio.h>

int main(){
	double x, y;
	char c1, c2, c3;
	int a1, a2, a3;
	
	scanf("%d%d%d", &a1, &a2, &a3);
	getchar();
	printf("a1 = %d, a2 = %d, a3 = %d\n", a1, a2, a3);
	
	scanf("%c%c%c", &c1, &c2, &c3);
 	printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);
	
	scanf("%lf%lf", &x, &y);
	printf("x = %lf, y = %lf\n", x, y);
	
	return 0;
}

实验结论

实验任务3

实验代码1

#include <stdio.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");
}
	return 0;
} 

实验代码2

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

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

实验结论


实验任务4

实验代码

#include <stdio.h>

int main(){
	char light,r,g,y;
	while(scanf("%c", &light) != EOF){
		getchar();
		if(light == 'r')
			printf("stop!\n");
		else if(light == 'g')
			printf("go go go\n");
		else if(light == 'y')
			printf("wait a minute\n") ;
		else
			printf("something must be wrong...\n");
	}
	
	return 0; 
}

实验结论

实验任务5

实验代码

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

int main(){
	srand(time(0));
	
	int a = rand()%30 + 1;
	int x;
	int i=1;
	printf("猜猜2023年4月哪一天会是你的lucky day\n\n");
	printf("开始喽,你有三次机会,猜吧(1~30):");
	
	while(i++<4){
		scanf("%d", &x); 
		if(x==a){
			printf("哇,猜中了:-)");
			break;}
		else if(x<a)
			printf("你猜的日期早了,你的lucky day还没到呢\n\n");
		else
			printf("你猜的日期晚了,你的lucky day已经过啦\n\n") ;
		if(i<3)
		printf("再猜(1~30):");
	}
return 0;
}

实验结论



实验任务6

实验代码

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

实验结论

实验任务7

实验代码

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

实验结论


标签:main,int,++,实验,printf,include
From: https://www.cnblogs.com/yggybb/p/17224916.html

相关文章

  • 实验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......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;srand(time......
  • 实验二
    task1#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;inti;srand(......
  • 跟烤冷面一起做SEO实验:开篇词
    我可怜的网站一切的起因都源于我去年年底创建的网站腐蚀脚本,既然建立了网站,总是希望有人看的,然而事实就是这么残酷,我的博客真的没有多少观众老爷捧场0.0这里我也不管我......
  • 带你全方面了解字节 A/B 实验的文化与工具
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 A/B测试是在相同的环境下,通过随机的抽样把对照组和控制组进行区分,并分别实行新......
  • 实验2
    task.1源码//task1.c#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;i......