Skip to content
Home » C program to find the maximum in the given two numbers using the conditional operator

C program to find the maximum in the given two numbers using the conditional operator

Learn about C program to find the maximum in the given two 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 maximum in the given two numbers using the conditional operator

Two numbers are taken as input from the user. Then maximum of two number if found using conditional operator and result is displayed.

Program:

#include<stdio.h>
int main()
{
  float num1, num2, max;

  printf("Enter two numbers: ");
  scanf("%d %d", &num1, &num2);

  max = (num1 > num2) ? num1 : num2;

  printf("Maximum of %d and %d is %d",num1, num2, max);

  return 0;
}

Output:

Enter two numbers: 8 4
Maximum of 8 and 4 is 8

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

Similar Codes :
C program to find the area of the circle, area of the triangle and area of the rectangle according to the user’s input choice
C program to checks whether a character entered by the user is a vowel or not by using the switch case statement