Q:-Write a C program to find the largest of three numbers
C program to find largest of three given numbers is discussed here. Input three integers from the user and find the largest number among them. Given three numbers num1,num2, and num3. The task is to find the largest number among the three.
#include<stdio.h> #include<conio.h> void main() { int num1, num2, num3; printf(" Enter the number1 = "); scanf("%d", &num1); printf("\n Enter the number2 = "); scanf("%d", &num2); printf("\n Enter the number3 = "); scanf("%d", &num3); if (num1 > num2) { if (num1 > num3) { printf("\n Largest number = %d \n",num1); } else { printf("\n Largest number = %d \n",num3); } } else if (num2 > num3) { printf("\n Largest number = %d \n",num2); } else { printf("\n Largest number = %d \n",num3); } getch(); }
#include<stdio.h> #include<conio.h> void main() { int num1, num2, num3; printf(" Enter the number1 = "); scanf("%d", &num1); printf("\n Enter the number2 = "); scanf("%d", &num2); printf("\n Enter the number3 = "); scanf("%d", &num3); if (num1 > num2) { if (num1 > num3) { printf("The 1st Number is the greatest among three. \n"); } else { printf("The 3rd Number is the greatest among three. \n"); } } else if (num2 > num3) printf("The 2nd Number is the greatest among three \n"); else printf("The 3rd Number is the greatest among three \n"); } getch(); }
#include<stdio.h> #include<conio.h> void main() { int num1, num2, num3; printf(" Enter the number1 = "); scanf("%d", &num1); printf("\n Enter the number2 = "); scanf("%d", &num2); printf("\n Enter the number3 = "); scanf("%d", &num3); if ((num1 > num2) && (num1 > num3)) printf("The 1st Number is the greatest among three. \n"); if ((num2 > num3) && (num2 > num1)) printf("The 2nd Number is the greatest among three \n"); if ((num3 > num1) && (num3 > num2)) printf("The 3rd Number is the greatest among three. \n"); } getch(); }
1. Take the three numbers and store it in the variables num1, num2 and num3 respectively.
2. Firstly check if the num1 is greater than num2.
3. If it is, then check if it is greater than num3.
4. If it is, then print the output as “num1 is the greatest among three”.
5. Otherwise print the ouput as “num3 is the greatest among three”.
6. If the num1 is not greater than num2, then check if num2 is greater than num3.
7. If it is, then print the output as “num2 is the greatest among three”.
8. Otherwise print the output as “num3 is the greatest among three”.