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;更节省资源!
#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--;
}
}
//******************************************************************************
//**************************找出两个数的最大值**********************************
//******************************************************************************
#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");
}
}