Also view this program using if else -
C program to find maximum between three numbers using if else.
Required knowledge:
Basic C programming, Conditional operatorProgram:
/** * C program to find maximum between three numbers using conditional operator */ #include <stdio.h> int main() { int num1, num2, num3, max; /* * Read three numbers from user */ printf("Enter three numbers: "); scanf("%d%d%d", &num1, &num2, &num3); /* Finds maximum between three */ max = (num1>num2 && num1>num3) ? num1 : (num2>num3) ? num2 : num3; printf("\nMaximum between %d, %d and %d = %d", num1, num2, num3, max); return 0; }
Output
Enter three numbers: 10
20
30
Maximum between 10, 20 and 30 = 30
20
30
Maximum between 10, 20 and 30 = 30
Happy coding ;)
You may also like
- C program to find maximum between two numbers using conditional operator
- C program to find maximum between two numbers using Switch case
- C program to check even or odd number using conditional operator.
- C program to check leap year using conditional operator.
- C program to check whether a character is alphabet or not using conditional operator.
- C program to create simple Calculator using switch case.
- C program to check whether a triangle is valid or not if all angles are given.
- C program to classify triangles as Equilateral, Isosceles or Scalene triangle.
- C program to print all natural numbers from 1 to n.
- C program to print all even numbers from 1 to n.
- C program to print table of any number.
- C program to print number in words.
- C program to check whether a number is Strong number or not.
- C program to check whether a number is Armstrong number or not.