郑州轻工业大学OJ刷题

  • 1000
#include<stdio.h>
 main(){
 	printf("从今天开始入坑C语言");
 }
  • 1001
#include<stdio.h>
main(){
	int a,b;
	scanf("%d %d", &a,&b);
	printf("%d", a+b);
}
  • 1002
#include<stdio.h>
#include<math.h>
main(){
	int x,y;
	scanf("%d",&x);
	y=2*pow(x,2)+x+8;
	printf("%d",y);
}
  • 1003
#include<stdio.h>
main(){
	/*
	和、差、积、整数商及余数
	*/
	int num1,num2;
	scanf("%d %d",&num1,&num2);
	//和
	printf("%d ",num1+num2);
	//差
	printf("%d ",num1-num2);
	//乘积
	printf("%d ",num1*num2);
	//商
	printf("%d ",num1/num2);
	//余数 
	printf("%d",num1%num2);
} 
  • 1004
#include<stdio.h>
main(){
	int num;
	int x,y,z;
	scanf("%d", &num);
	x = num % 10;	//个位数
	y = (num % 100 - x) / 10;//十位  或者(n/10)%10
	z = num / 100;//(n/100)%10
	printf("%d %d %d",x,y,z);
	return 0;
}
  • 1005
#include<stdio.h>
#include<math.h>
int main(){
	int x,y,z;
	scanf("%d %d %d", &x, &y, &z);
	//注意pow()返回值为double,需要强转
	printf("%-9d%-9d%-9d\n",x,(int)pow(x,2),(int)pow(x,3));
	printf("%-9d%-9d%-9d\n",y,(int)pow(y,2),(int)pow(y,3));
	printf("%-9d%-9d%-9d",z,(int)pow(z,2),(int)pow(z,3));
	return 0;
}
  • 1006
#include<stdio.h>
main(){
	/*输入三个整数,之间用空格隔开。
	第1个数作为首项,第2个数作为末项,第3个数作为公差。
	通项公式为:an=a1+(n-1)*d
	前n项和公式为:Sn=a1*n+[n*(n-1)*d]/2或Sn=[n*(a1+an)]/2。
	*/
	int a1,an,d;
	int result;
	int t = 0;
	scanf("%d %d %d", &a1,&an,&d);
	t = a1;
	result = an;
	while(t!=an){
		result = result + t;
		t = t + d;
	}
	printf("%d",result);
	
}
  • 1007
#include<stdio.h>
#include<math.h>
int main(){
	//鸡兔同笼,数学方法
	int m,n,x,y;
	scanf("%d %d", &m,&n);
	x = 2*m - n/2;
	y = n/2 - m; 
	printf("%d %d",x,y);
	return 0;
} 
  • 1008
#include<stdio.h>
int main(){
	/*
	假设美元与人民币的汇率是1美元兑换6.5573元人民币,
	编写程序输入美元的金额,
	输出能兑换的人民币金额。
	*/
	double money = 0;
	scanf("%lf",&money);
	money = money * 6.5573;
	printf("%.2lf",money);
}
  • 1009
#include<stdio.h>
int main(){
	/*
	某位学生的数学、英语和计算机课程的成绩,
	求该生三门课程的平均分。
	*/
	int math,english,computer;
	float average;
	scanf("%d %d %d",&math,&english,&computer);
	average = (math+english+computer)/3.00;
	printf("%.2f",average);
	return 0;
}
  • 1010
#include<stdio.h>
#include<math.h>
int main(){
	/*
	求圆的周长和面积
	输入圆的半径,求圆的周长和面积。 
	要求定义圆周率为如下宏常量
	#define PI 3.14159
	*/
	#define PI 3.14159
	float r;
	double s, c;
	scanf("%f", &r);
	c = 2 * PI * r;
	s = PI * pow(r , 2);
	printf("%.2lf %.2lf", c, s);
	return 0;
} 
  • 1011
#include<stdio.h>
#include<math.h>
int main(){
	/*
	输入圆柱体的底面半径r和高h,
	计算圆柱体的表面积并输出到屏幕上。
	要求定义圆周率为如下宏常量
	#define PI 3.14159
	*/
	#define PI 3.14159
	float r, h;
	double s ;
	scanf("%f %f", &r, &h);
	s = 2 * PI * pow(r,2) + 2 * PI * r * h;
	printf("%.2lf",s);
	return 0;
}
  • 1012
#include<stdio.h>
#include<math.h>
int main(){
	/*
	求实数的绝对值。
	*/
	float a;
	scanf("%f", &a);
	printf("%.2f", fabs(a));
	//fabs()求浮点数的绝对值
	return 0;
}
  • 1013
#include<stdio.h>
#include<math.h>
int main(){
	/*
	给定A(x1, y1), B(x2, y2)两点坐标,计算它们间的距离。
	
	*/
	float x1,x2,y1,y2;
	float d;
	scanf("%f %f %f %f", &x1,&y1,&x2,&y2);
	d = sqrt(pow((y1-y2),2)+pow((x1-x2),2));
	printf("%.2f",d);
}
  • 1014
#include<stdio.h>
#include<math.h>
int main(){
	/*
	 输入三角形的三条边长(实数)
	 求三角形的面积。
	 海伦公式:
	设P=(a+b+c)/2 则:面积S=√p(p-a)(p-b)(p-c)
	*/
	float a,b,c;
	float p, s;
	scanf("%f %f %f", &a,&b,&c);
	p = (a+b+c)/2.00;
	s = sqrt(p*(p-a)*(p-b)*(p-c));
	printf("%.2f",s);
	
} 
  • 1015
#include<stdio.h>
#include<time.h>
int main(){
	/*
	读入两个用“时:分:秒”表示的时间点,
	计算以秒为单位的时间间隔。
	*/
	int a,b,c,time1;
	int d,e,f,time2;
	scanf("%d:%d:%d", &a, &b, &c);
	scanf("%d:%d:%d", &d, &e, &f);
	time1 = a * 3600 + b * 60 + c;
	time2 = d *	3600 + e * 60 + f;
    printf("%d", time2 - time1);
	return 0;
}
  • 1016
#include<stdio.h>
int main(){
	/*
	设银行1年期定期存款年利率为2.25%,
	存款本金为capital元,试编程计算并输出n年后的本利之和。
	(注: 目前银行活期存款的利息是按单利计息的。
	如果是定期存款,连本带息转入下一个存期,
	那么会继续计入定期的,相当于是复利。)
	*/
	double capital;
	int year;
	scanf("%d %lf", &year, &capital);
	while(year){
		capital = (1+0.0225) * capital;
		year--;
	}
	printf("%.6lf",capital);
	return 0;
}
  • 1017
#include<stdio.h>
int main(){
	/*
	给定一个不多于5位的正整数,判断它是几位数,并输出。
	*/
	int num,n;
	scanf("%d", &num);
	if(num / 10000 != 0) n = 5;
	else if(num / 1000 !=0) n = 4;
	 else if(num / 100 !=0) n = 3;
	 	else if(num / 10 !=0) n = 2;
	 		else n = 1;
	printf("%d", n);
	
}
  • 1018
#include<stdio.h>
int main(){
	/*
	输入一个整数,判断该数是奇数还是偶数。
	*/
	int n;
	scanf("%d", &n);
	if(n%2==0){
		printf("even");
	}else{
		printf("odd");
	}
	
}
  • 1019
#include<stdio.h>
int main(){
	/*
	某公园门票的票价是每人50元,
	一次购票满30张,每张可以少收2元。
	试编写自动计费系统程序。
	*/
	
	int number;//购票数量
	int money;
	scanf("%d", &number);
	if(number<30){
		money = number * 50;
	} else{
		money = number * (50-2);
	}
	printf("%d",money);
	return 0;
}
  • 1020
#include<stdio.h>
int main(){
	/*
	从键盘输入两个整数x,y,按从小到大的顺序输出它们的值。 
	*/
	int x,y;
	scanf("%d %d",&x,&y);
	if(x<y){
		printf("%d %d",x,y);
	}else{
		printf("%d %d",y,x);
	}
	return 0;
}
  • 1021
#include<stdio.h>
int main(){
	/*
	输入三个整数x,y和z,求出其中最大的数。
	*/
	int a,b,c;
	int max;;
	scanf("%d %d %d", &a, &b, &c);
	max = a;
	if(max < b){
		max = b;
	}
	if(max < c){
		max = c; 
	}
	printf("%d",max);
	return 0;
}
  • 1022
#include<stdio.h>
int main(){
	/*
	输入三个整数x,y和z,按从大到小的顺序输出它们的值。
	*/ 
	int a,b,c;
	scanf("%d %d %d",&a, &b,&c);
	int d;
	if(a < b){
		d = a;
		a = b;
		b = d;
	}
	if(c > a){
		d = a;
		a = c;
		c = d;
	} 
	if (c > b){
		d = c;
		c = b;
		b = d;
	}
	printf("%d %d %d",a,b,c);
	return 0;
	
}
  • 1023
#include<stdio.h>
int main(){
	/*
	输入一个字符,若是小写字母,则变为大写输出,否则,原样输出。
	*/
	char a;
	scanf("%c",&a);
	if(a>=97){//小写 
	a = a - 32; 
	}
	printf("%c",a);
	return 0;
}
  • 1024
#include<stdio.h> 
int main(){
	/*
	输入一个英文字母(可能是大写,也可能是小写),
	输出该字母在字母表中的序号(’a’和’A’的序号为1)。
	A 65
	a 97
	*/
	
	int index;
	char s;
	scanf("%c",&s);
	if(s>=97){//小写 
		s = s - 32; 
	}
	printf("%d",s-64);
	
}
  • 1025
在这#include<stdio.h>
int main(){
	/*
	给你三个ASCII字符(不含空白字符:包括空格、制表符\t、回车换行符\n),
	找出其中最大的那个
	*/
	char a,b,c;
	char max;
    scanf("%c %c %c",&a,&b,&c);
	if(a > b) max = a;
	else max = b;
	if(c > max) max = c; 
	printf("%c",max);
	return 0;
} 里插入代码片
  • 1026
#include<stdio.h>
int main(){
	/*
	从键盘输入一个字符,判断该字符
	是否大写字母、小写字母、数字字符或其他字符。
	分别输出对应的提示信息。
	*/
	char a;
	scanf("%c",&a);
	if('A'<= a && a<='Z'){
		printf("upper");
	}else if('a'<= a && a<='z'){
		printf("lower");
	}else if('0'<= a && a<='9'){
		printf("digit");
	}else printf("other");
	return 0;
}
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值