Skip to content
Home » C program to find the largest among three numbers using the conditional operator

C program to find the largest among three numbers using the conditional operator

Learn about C program to find the largest among three numbers using the conditional operator in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C program to find the largest among three numbers using the conditional operator

Program:

#include<stdio.h>
int main()
{
  float a, b, c, max;
  printf("Enter three numbers: ");
  scanf("%d %d %d",&a, &b, &c);
  max = (a>b && a>b)? a: (b>a && b>c)? b:c;
  printf("Maximum number = %d",max);
  return 0;
}

Output:

Enter three numbers: 3 1 7
Maximum number = 3

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
program to enter two numbers. Make a comparison between them with the conditional operator in C
Program to Find the minimum of two numbers using the conditional operator in C