山东春季高考-C语言技能题(完结)

[软件第一场]2024年3月9号 8:00-9:00场

//1.程序改错(3个空)        指针指向字符串 

//2.程序填空    整型数据,求出个位和十位,然后输出十位和个位的乘积 

//3.程序编写1  二维数组,三行四列,输出将每行的平均值放在一个一维数组
//(输入12个整数,填入3行4列数组,然后求每行平均,存到一维数组输出)
#include<stdio.h>
int main(){
	int a[3][4];
	float avg[3];
	int i,j;
	for(i=0;i<3;i++){
		float sum=0;
		for(j=0;j<4;j++){
			scanf("%d",&a[i][j]);
			sum+=a[i][j];
		}
		avg[i]=sum/4;
	}
	for(i=0;i<3;i++)	
		printf("%f\n",avg[i]);
	return 0;	
} 
//4.程序编写2  
//分支语句,卖图书,周一至周五7折,周六8折,周日9折,输入天数,图书数,输出价格。
//根据天数判断星期几,假设一周从1开始计数(1代表周一,7代表周日)
#include<stdio.h>
int getweek(int day){
	return (day%7)+1;
}
	float fun(int count,float price,int day){
		float rate;
		switch(getweek(day)){
			case 1:
			case 2:
			case 3: 
			case 4: 
			case 5: rate=0.7;break;
			case 6: rate=0.8;break;
			case 7: rate=0.9;break;
			default: printf("输入无效天数\n"); break;  
		}
		return count*price*rate;
	}
int main(){
	int day,count;
	float price;
	printf("请输入天数(1代表周一,7代表周日):");
	scanf("%d",&day);
	printf("请输入图书数量:");
	scanf("%d",&count);
	printf("请输入每本书的原价:");
	scanf("%f",&price);
	float totalprice=fun(count,price,day);
	printf("应付的价格为:%.2f元\n",totalprice);
	return 0;
} 

[软件第二场]C语言 9号 10:30-11:30场次

//1.程序改错(3个空)         用两指针求一组数的最小值,一开始均指向首地址,
//指针p不动,指针q往后加加,遇见小的数,就让p指该位置

//2.程序填空        switch语句,输入1是是开,输入2是关,输入其他就default

//3.程序编写1    主函数输入乒乓球数,子函数判断装盒数并返回
//若是偶数就两个装一盒,若是奇数就五个装一盒,多余的球再往外装一盒,问一共要几个盒 
#include<stdio.h>
int fun(int totals){
	int evenboxes=totals/2;
	int oddballs=totals%2;
	int oddboxes=oddballs>0?(oddballs+4)/5:0;
	if(oddballs%5!=0)	oddboxes++;
	return evenboxes+oddboxes;
}
int main(){
	int totals;
	printf("请输入乒乓球的总数:");
	scanf("%d",&totals);
	int boxcount=fun(totals);
	printf("共需要%d个盒子\n",boxcount);
	return 0;
} 
//4.程序编写2  
//一个由x,y,z三个数字(0~9的数字)组成的数xyz以及逆序数zyx相加得1555,求x、y、z
#include<stdio.h>
int check(int x,int y,int z){
	int number1=100*x+10*y+z;
	int number2=100*z+10*y+x;
	return number1+number2==1555;
} 
int main(){
	for(int x=0;x<=9;x++){
		for(int y=0;y<=9;y++){
			for(int z=0;z<=9;z++){
				if(check(x,y,z)){
					printf("xyz的值分别为:%d%d%d\n",x,y,z); 
				}
			}
		}
	}
} 

[网络第一场]2024年3月9号 8:00-9:00场

//程序填空1.题目中已有输入的两行单词,输出其中为奇数位的部分
#include<stdio.h>
#include<conio.h>
#define MAX 20
int main(){
	char word1[MAX],word2[MAX];
	gets(word1);
	gets(word2);
	for(int i=0;word1[i]!='\0';i++)
		if(i%2!=0)	printf("%c",word1[i]);
	printf("\n");
	for(int i=0;word2[i]!='\0';i++)
		if(i%2!=0)	printf("%c",word2[i]);
	printf("\n");
	return 0;
}
//程序填空2.给了三个定义好的字符串,判断是否符合规则(代码缺失)

[网络第二场]C语言 9号 10:40-11:40场次

//1.程序填空1  给定一个数组s存储字符串,从中获取ASCII码值为奇数的值并输出 
#include<stdio.h>
#include<string.h>

#define MAX_SIZE 100

int main(){
	char s[MAX_SIZE] = "Your array content goes here";
	int length=strlen(s);
	for(int i=0;i<length;i++)
		if((int)s[i]%2 != 0)
			printf("%c",s[i]);
	return 0;
}
//2.程序填空2
//判断用户设置的用户名是否大于8位并小于20位(包含8和20) 
//要求用户名设置的内容必须是大写小写字母+数字
#include<stdio.h>
#include<string.h>
int check(char str[]){
	int len=strlen(str);
	if(len<8 || len>20)	return 0;
	int i,flag=0;
	for(i=0;i<len;i++){
		if(str[i]>48 || str[i]<57)			flag=1;
		else if(str[i]>65 || str[i]<90)		flag=1;
		else if(str[i]>97 || str[i]<122)	flag=1;
	}
	if(flag) return 1;
	else return 0;
}
int main(){
	char username[21];
	printf("请输入用户名:");
	gets(username);
	if(check(username))	
		printf("用户名通过验证\n");
	else 
		printf("用户名不符合要求\n");
	return 0;
}

[软件第三场]2024年3月9号 13:00-14:00场

//1.程序改错    0~9组成的不重复三位数的个数(for循环ijk,一堆if、else、continue)
//2.程序填空    10个数的正逆输出,填的是逆输出用的函数
//3.程序编写1    输出10~50中个位和十位乘积大于个位和十位之和的数
#include<stdio.h>
int main(){
	for(int i=10;i<=50;i++){
		int a=i/10;
		int b=i%10;
		if(a*b>a+b)
			printf("%d的个位和十位乘积大于个位和十位之和\n",i); 
	}
	return 0; 
}
//4.程序编写2
//九个已经按照升序排完的字母放在一维数组中,插入一个字母,使得其依然有序,并输出
#include<stdio.h>
void insert(char str[],char new_str){
	int i;
	for(i=0;i<9 && str[i]<new_str;i++);
		for(int j=9;j>i;j--){
			str[j]=str[j-1];
		}	
		str[i]=new_str;
	printf("插入新字母后的排序为:");
	for(int k=0;k<10;k++){
		printf("%c",str[k]);
	}
	printf("\n");
}
int main(){
	char str[10]={'a','b','c','d','e','f','g','h','i'};
	char new_str;
	scanf("%c",&new_str);
	insert(str,new_str);
	return 0;
}

[网络第三场]2024年3月9号 14:00-15:00场

//1.程序填空1 
//输入一串字符,长度不超过20,判断是否回文(字符数组)
#include<stdio.h>
#include<string.h>
int  check(char str[]){
	int len=strlen(str);
	int start=0;
	int end=len-1;
	while(start<end){
		if(str[start]!=str[end])	return 0;
		start++;
		end--;
	}
}
int main(){
	char str[21];
	printf("请输入一个长度不超过20的字符串(不含空格):");
	gets(str);
	if(check(str))	printf("该字符串回文\n");
	else printf("该字符串不回文\n");
}
//2.程序填空2
//有三家商店,四个月的销量,计算出月销量的平均值,求哪一家商店是销冠,二维数组
#include<stdio.h>
int main(){
	int sales[3][4];
	int total_sales[3]={0};
	float avg[4]={0.0f};
	int max_shop=0;
	int max_sales=0;
	
	int month,shop;
	for(month=0;month<4;month++){
		int month_tatol=0;
	for(shop=0;shop<3;shop++){
		month_tatol=sales[shop][month];
	}
	avg[month]=(float)4/3; 
	}
	
	for(month=0;month<4;month++){
	for(shop=0;shop<3;shop++){
		total_sales[shop]+=sales[shop][month];
	}
	if(total_sales[shop]>max_sales){
		max_sales=total_sales[shop];
		max_shop=shop;
		}
	}
	
	printf("每月平均销量:\n");
	for(month=0;month<3;month++){
		printf("第%d个月的平均销量:%.2f\n",month+1,avg[month]);
	}
	 
	 printf("总销量最高的商店编号是%d,总销量是%d\n",max_shop+1,max_sales);
	 return 0;
} 

[软件第四场]2024年3月9号 15:00-16:00场

//1.程序改错
//输入两个数,从小到大输出(有一个中间变量用于交换)
#include<stdio.h>
int main(){
	int x,y,temp,*p,*q;
	scanf("%d%d",&x,&y);
	p=&x;
	q=&y;
	if(*p>*q){
		temp=*p;
		*p=*q;
		*q=temp;
	}
	printf("%d,%d",*p,*q);
} 
//2.程序填空	求1~n的阶乘
#include<stdio.h>
int main(){
	int n,i,j;
	double s;
	printf("请输入整数n:\n");
	scanf("%d",&n);
	printf("1~%d的阶乘为:",n);
	for(i=0;i<=n;i++){
		s=1;
		for(j=1;j<=i;j++){
			s*=j;
		}
	printf("%d的阶乘为:%0.f\n",i,s);
	}
}
//3.程序编写1
//输入三条边,判断能不能构成三角形 ,如果是三角形,判断是不是直角三角形
#include<stdio.h>
int check(double a,double b,double c){
	if(a+b>c&&b+c>a&&a+c>b)	return 1;
	else return 0;
}

int check_z(double a,double b,double c){
	if(a>=b){
		if(a>=c){
			if(b*b+c*c==a*a)	return 1;
		}else{
			if(a*a+b*b==c*c)	return 1;
		}
	}else{
			if(b>=c){
				if(a*a+c*c==b*b)	return 1;
			}else{
				if(a*a+b*b==c*c)	return 1;
			}
		}
		return 0;
}

int main(){
	double a,b,c;
	printf("请输入三角形的三条边:\n");
	scanf("%lf %lf %lf",&a,&b,&c); 
	if(check(a,b,c)){
		if(check_z(a,b,c))	
			printf("该三边可以构成直角三角形。\n"); 
		else  
			printf("该三边可以构成非直角三角形。\n");
	}else  
		printf("该三边不能构成三角形。\n");
	return 0; 
}
//4.程序编写2
//使用函数调用,输出三个数之间的最大值
#include<stdio.h>
int max(int a,int b,int c){
	int max=a;
	if(b>max)	max=b;
	if(c>max)	max=c;
	return max;
}
int main(){
	int num1,num2,num3;
	printf("请输入三个整数(以空格分隔):\n");
	scanf("%d %d %d",&num1,&num2,&num3);
	int MAX=max(num1,num2,num3);
	printf("这三个数中的最大值是:%d\n",MAX);
	return 0; 
}

[软件第四场]2024年3月9号 17:00-18:00场

//1.程序改错	十个数求平均数
#include<stdio.h>
int main(){
	float numbers[10],sum=0.0f;
	int i;
	for(i=0;i<10;i++){
		printf("请输入第%d个数",i+1);
		scanf("%f",&numbers[i]);
		sum+=numbers[i];
	}
	float avg=sum/10.0f;
	printf("这十个数的平均数是:%.2f\n",avg);
	return 0;
}
//2.程序填空
//一串字符This *is c *program运行到*就删除,然后把后面的字符往前移
#include<stdio.h>
#include<string.h>
void fun(char str[],int pos){
	if(pos<0 || pos>strlen(str)){
		printf("位置错误。");
		return;
	}
	for(int i=pos;str[i]!='\0';i++){
		str[i]=str[i+1];
	}
	str[strlen(str)-1]='\0';	
}
int main(){
	char str[]="This *is c *program";
	int pos=8;
	fun(str,pos);
	printf("移动的开始位置为%d,移动后的字符串为:%s",pos,str);
	return 0;
}
//3.程序编写1
//输入近视度数,判断是不是近视,就比如大于等于100小于300就输出轻度近视 
#include<stdio.h>
int main(){
	int du;
	printf("请输入你的近视度数:\n");
	scanf("%d",&du);
	if(du>=100 && du<300){
		printf("你属于轻度近视\n"); 
	}else{
		printf("根据你输入的度数,无法确定为轻度近视,请确保度数在100到300之间。\n"); 
	}
} 
//4.程序编写2
//输密码 密码是666666 输入的数正确就输出
//输入的数不正确就输出密码错误  错误次数等于4次时,就输出密码锁定
#include<stdio.h>
#include<string.h>
#define password "666666"
int main(){
	int attempts=0;
	char str[7];
	while(attempts<4){
		printf("请输入密码:");
		gets(str);
		if(strcmp(str,password)==0){
			printf("密码正确\n");
			return 0; 
		}else{
			printf("密码错误\n");
			attempts++;
		}	
	}
	printf("密码锁定\n");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值