/* Program to find largest number from the three numbers entered by the user. */
if (num1>=num2 && num1>=num3) // comparison of first number with second and third number
#include <stdio.h>
#include <conio.h>
void main()
{
int num1, num2, num3, max;
clrscr(); //for clearing the console screen
//Taking three numbers as input
printf("Enter three numbers: ");
scanf("%d %d%d", &num1, &num2, &num3);
//Logic for finding largest numbers from three entered by user
if (num1>=num2 && num1>=num3) // comparison of first number with second and third number
{
max=num1;
max=num1;
}
else if (num2>=num1 && num2>=num3)// comparison of second number with first and third number
{
{
max=num2;
}
else
else
{
max=num3; /*since other two numbers are smaller then this third number so it will be largest */
}
printf("Largest number = %d", max);
printf("Largest number = %d", max);
getch(); //for holding the console screen
}
No comments:
Post a Comment