C Program to Find Largest Number Among Three Numbers

Write a C Program that Ask for Three Numbers and Find the Largest Number

In this tutorial, we will learn How to find largest number among the three numbers.

This problem consists of, when the program is run, it will ask three space-separated numbers in the console. After then it will output as follows: “The maximum number is: max” where max is the largest number.

Algorithm – Find Largest Number

• In the main function, we will declare a total of 4 integer variables, three (`a`, `b`, `c`) for taking three integer values and the remaining one (`max`) for putting the maximum number in it.
• The ask for three space-separated numbers using the `scanf()` function and ensure that the values are stored correspondingly in variables a, b, and c.
• Write the Business Logic to find the maximum number using if-else conditions
• After finding the number put that number in the `max` variable.
• Finally, display the number in the console using `printf()` function.

Program – FInd Largest Number

``````#include <stdio.h>
int main()
{
int a, b, c, max;
printf("Enter three space-separated numbers: ");
scanf("%d%d%d", &a, &b, &c);

if ((a > b) && (a > c)) {
max = a;
} else if (b > c) {
max = b;
} else {
max = c;
}

printf("The maximum number is: %d\n", max);
return 0;
}``````
Sample Input Sample Output
Enter three space-separated numbers: 5 9 2 The maximum number is: 9
Enter three space-separated numbers: 150 44 109 The maximum number is: 150

Happy Coding đź™‚

Posted in