C语言 找出两个数的最大值

2024-12-31 15:17:52
推荐回答(3个)
回答1:

int main()
{
int a,b,max;
scanf("%d%d",&a,&b);
if(a>b)

max=a;

else

max=b;

printf("%d",max);
getch();
}
或者把if和printf之间改为max=(a>b)?a:b;更节省资源!

回答2:

#include "stdio.h"
main()
{
int n,a,b;
scanf("%d",&n);
while(n>0)
{
scanf("%d %d",&a,&b);
if(a>b)
printf("%d",a);
else if(a printf("%d",b);
else
printf("These numbers are equal.");
n--;
}
}

回答3:

//******************************************************************************
//**************************找出两个数的最大值**********************************
//******************************************************************************
#include
int main()
{
int num, n, m;
scanf("%d", &num);
while(num--)
{
scanf("%d%d", &n, &m);
if(n > m)
printf("%d\n", n);
else if(n < m)
printf("%d\n", m);
else
printf("These numbers are equal.\n");

}
}