Write a program to take three numbers as input from users and find a greatest numbers from three.
For example: Let three numbers are 34965, 34750, 34068
Then the greatest number is 34965.
Program to find greatest number
printf("Enter the three numbers\t");
if(num1 > num2 && num1 >num3)
printf("%d is greatest number",num1);
else if(num2 >num1 && num2>num3)
printf("%d is greatest number ",num2);
else if(num3>num1 && num3>num2)
printf("%d is greatest number ",num3);
Enter the three numbers
860375 is greatest number
In first if we check number1 is greater than number2 and number3. If number1 is greater, then first if statement will execute and print ‘number1 is greater number’.
Otherwise corresponding else statement will execute.
In second else-if statement, we are checking number2 is greater than number1 and number3.
If condition is true then it print number2 is greater. Else the third else-if statement will execute.
In this way we will get greatest number from three numbers.
Note: If you dont know what is && and how it work then refer Operators.