Second Max of Three Numbers | Problem - 9 | Beginner level | C language | CodeChef
Link to the problem statement: https://www.codechef.com/submit-v2/MINHEIGHT
Solution:
#include <stdio.h>
int main(void) {
int t, a, b, c, i;
scanf("%d", &t);
for(i=0;i<t;i++)
{
scanf("%d %d %d", &a, &b, &c);
if ( a !=b && a != c && b != c )
{
if( a > b && a > c )
{
if( b > c )
printf("%d\n",b);
else
printf("%d\n",c);
}
else if( b > a && b > c )
{
if( a > c )
printf("%d\n",a);
else
printf("%d\n",c);
}
else if( c > a && c > b )
{
if( a > b )
printf("%d\n",a);
else
printf("%d\n",b);
}
}
}
return 0;
}
int main(void) {
int t, a, b, c, i;
scanf("%d", &t);
for(i=0;i<t;i++)
{
scanf("%d %d %d", &a, &b, &c);
if ( a !=b && a != c && b != c )
{
if( a > b && a > c )
{
if( b > c )
printf("%d\n",b);
else
printf("%d\n",c);
}
else if( b > a && b > c )
{
if( a > c )
printf("%d\n",a);
else
printf("%d\n",c);
}
else if( c > a && c > b )
{
if( a > b )
printf("%d\n",a);
else
printf("%d\n",b);
}
}
}
return 0;
}
Hope this will help you, if you want anything else leave a comment.
Thank you
Comments
Post a Comment