In this C program, we will find maximum of the two numbers using switch statement. We will first take two numbers as input from user using scanf function. Then we print the maximum number on screen using switch case statement.
Required Knowledge
C program to find maximum of two numbers using switch case statement
#include <stdio.h> int main() { int a, b; printf("Enter Two Integers\n"); scanf("%d %d", &a, &b); switch(a > b) { /* a>b comparison returns true(1) */ case 1: printf("%d is Maximum", a); break; /* a>b comparison returns false(0) */ case 0: printf("%d is maximum", b); break; } return 0; }Output
Enter Two Integers 4 8 8 is Maximum
Enter Two Integers -2 -4 -2 is Maximum
Related Topics