栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言程序设计小练02

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言程序设计小练02

1. 键盘输入两个数,比较两个数的大小,并输出较大的数

#include
int main()
{
int x, y;
printf("请输入两个整数:");
scanf("%d%d", &x, &y);
if (x> y)
printf("MAX=%dn", x);
else
printf("MAX=%dn", y);
return 0;
}

2. 键盘输入三个数,比较三个数的大小,并按照从小到大顺序输出

#include 
#include
using namespace std;
int main() {
	int a,b,c,x;
	 cin>>a>>b>>c;
	 if(a>b) {
	 	x=a;
	 	a=b;
	 	b=x;	
	 } 
	 
	 if(a>c) {
	 	x=a;
	 	a=c;
	 	c=x;
	 }  if(b>c) {
	 	x=b;
	 	b=c;
	 	c=x;
	 }
	 cout<

3. 从键盘输入3个整数a,b,c的值,输出其中最大值。

#include
using namespace std;
int main()
{
	int a, b, c, max;
	cout << "输入三个整数" << endl;
	cin >> a >> b >> c;
	//运用 条件运算符
	max = (((a > b) ? a : b) > c) ? ((a > b) ? a : b) : c;
	cout << "最大的数为:" << max << endl;
}

4. 输入一个字符,若是小写字母,则转换为大写字母,否则不转换。最后输出。

#include
int main()
{
char x;
scanf("%c",&x);
if(x >= 97)
{
printf("%c",x - 32);
}
else
{
printf("%c",x);
}
return 0;

}

5. 键盘输入任意一个字符,判断是字母,数字或者空格 

#include
int main()
{
int x, y;
printf("请输入两个整数:");
scanf("%d%d", &x, &y);
if (x> y)
printf("MAX=%dn", x);
else
printf("MAX=%dn", y);
return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/629799.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号