
按顺序先后比较四个数的大皮谈小然后找出最大值即可实现功能。
范例:燃败碰
#include<stdio.h>void main()
{
int a, b, c, d, tem
printf("input four numbers:\n")
scanf("%d,%d,%d,%d",&a,&b,&c,&枯中d)
if(a>b)
{tem=aa=bb=tem}
if(a>c)
{tem=aa=cc=tem}
if(a>d)
{tem=aa=dd=tem}
if(b>c)
{tem=bb=cc=tem}
if(b>d)
{tem=bb=dd=tem}
if(c>d)
{tem=cc=dd=tem}
printf("%d,%d,%d,%d",a,b,c,d)
}
Ps:
常用排序方法如图:
上面的范例是以冒泡法编写的程序。
C语言程序设计比败胡友较两察槐个数的大小的方法:1
输入两个数值。
2
比较大小。
3
输出结果。
以整型为例,代码如下:
#include
int
main()
{
int
a,b
scanf("%d%d",&a,&b)
if(a>b)
printf("%d>%d\n",a,b)
else
if(a
==
b)
printf("%d=%d\n",a,b)
else
printf("%d<做简%d\n",a,b)
}
如何只是比较大小的话,直接一姿缺个判断就ok了。
代码如下:
#include <stdio.h>
int main()
{
int a=0,b=0
scanf("%d %d",&a,&b)
if(a>b)
printf("%d >%d\n",a,b)
else if (a<b)
printf("%d <%d\n",a,b)
else
printf("相等\n")
return 0
}
分析毕键:定义两个变量,然后输入它们,用if判断它们的大小然后用输出语句输迹数辩出结果。
结果图:
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)