C语言运算符与选择结构

1、输入任意两个数,请从小到大输出

#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
	int a,b;
	printf("请输入两个数:");
	scanf("%d %d",&a,&b);
	if(a<b)
		printf("%d %d",a,b);
	else
	{
		a=a+b;
		b=a-b;
		a=a-b;
		printf("%d %d",a,b);
	}
	return 0;
}

【输入样例】
55 24
【输出样例】
24 55

2、计算三个数的最大值

#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
	int a,b,c;
	int max;
	printf("请输入三个数:");
	scanf("%d %d %d",&a,&b,&c);
	max=a;
	if(max<b)
		max=b;
	if(max<c)
		max=c;
	printf("%d是最大值\n",max);
	return 0;
}

【输入样例】
55 8 23 
【输出样例】
55是最大值

3、输入一个字符如果是大写转换小写,如果是小写转换大写,如果是数字输出平方,如果是特殊字符则直接输出

#include <stdio.h>
#include <string.h>
#include <math.h>
int main(int argc, const char *argv[])
{
	char c;
	printf("请输入一个字符:");
	scanf("%c",&c);
	if(c>='A'&&c<='Z')
		printf("%c",c+32);
	else if(c>='a'&&c<='z')
		printf("%c",c-32);
	else if(c>='0'&&c<='9')
		printf("%.0f",pow(c-'0',2));
	else
		printf("%c",c);
	return 0;
}

【输入样例】
a
【输出样例】
A
【输入样例】
A
【输出样例】
a
【输入样例】
9
【输出样例】
81
【输入样例】
`
【输出样例】
`

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值