这题不会做,饭都不想吃,初学者!

来源:百度知道 编辑:UC知道 时间:2024/05/02 17:52:42
C语言编程:
从键盘输入4个数,将其中最大的字母输出.

用冒泡法做的:
#include <iostream.h>
void swap(int &x,int &y)
{
int temp;
temp = x;
x = y;
y = temp;
}
void main()
{
int a[4];
cout<<"Input 4 Numbers:";
cin>>a[0]>>a[1]>>a[2]>>a[3];
for(int i = 1;i < 4;i++)
{
if(a[i] <= a[i-1])
{
swap(a[i],a[i-1]);
}
}
cout<<a[3];
}

两两比较,舍小取大。
四个数的话比较三次就可以了。

只会数字的不是会字母的!!!晕死