2022-8-29 作业

第一题:从终端输入一个字符:如果是大写的 转换成小写,如果是小写的 转换成大写,如果是 0-9   按照 %d  输出对应整型的  0-9,其他字符 转换成 #并输出。

#include <stdio.h>
int main(){
	char input;
	while(1){
		printf("请输入字符: ");
		scanf(" %c",&input);
		if( input >= 48 && input <= 57 )
		{
			printf("输出:%d\n",input - 48);
		}
		else if( input >= 65 && input <= 90 )
		{
			printf("输出:%c\n",input + 32);
		}
		else if( input >= 97 && input <= 122 )
		{
			printf("输出:%c\n",input - 32);
		}
		else 
		{
			printf("#\n");
		}
	}
	
	return 0;
}

第二题:学生成绩管理
输入一个学生的成绩
[90,100]  A
[80,90) B
[70,80) C
[60,70) D
[0,60) 不及格
其他 输入错误

#include <stdio.h>
int main(){
	float input;
	while(1){
		printf("请输入学生成绩:");
		scanf(" %f",&input);
		if( input >= 90 && input <= 100 )
		{
			printf("等级:A\n");
		}
		else if( input >= 80 && input < 90 )
		{
			printf("等级:B\n");
		}
		else if( input >= 70 && input < 80 )
		{
			printf("等级:C\n");
		}
		else if( input >= 60 && input < 70 )
		{
			printf("等级:D\n");
		}
		else if( input >= 0 && input < 60 )
		{
			printf("不及格\n");
		}
		else
		{
			printf("输入错误\n");
		}
	}
	
	return 0;
}

第三题:输入一个年份  判断是平年还是闰年,闰年:能被4整除且不能被100整除   或者能被400整除,

#include <stdio.h>
int main(){
	int input;
	while(1){
		printf("请输入年份:");
		scanf(" %d",&input);
		if( input % 4 == 0 && input % 100 != 0 || input % 400 == 0)
		{
			printf("%d年是闰年\n",input);
		}
		else
		{
			printf("%d年是平年\n",input);
		}
	}
	return 0;
}

第四题: 输入一个三位数,判断是不是水仙花数,水仙花数(个位的三次方+十位的三次方+百位的三次方=数本身)

#include <stdio.h>
int main(){
	int input;
	while(1){
		printf("请输入一个三位数:");
		scanf(" %d",&input);
		int a = input / 100;
		int b = (input - (100*a)) / 10;
		int c = (input - (100*a)) % 10;
		if( a*a*a + b*b*b + c*c*c == input)
		{
			printf("%d是水仙花数\n",input);
		}
		else
		{
			printf("%d不是水仙花数\n",input);
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值