Greatest of Three Numbers in C language
Hi friends, in this tutorial, you will learn how to write a program to find the greatest of three numbers in C language.
Also read, Biggest of two numbers in C language
The logic of the program:-
- Initially, we will declare four integer variables such as a,b,c, and another integer variable “big”.
- Now, we will assume ‘a’ is biggest than ‘b’ and ‘c’ and stored to the resultant variable ‘big’.
- Now, ‘b’ is compared with the resultant variable ‘big’. If ‘b’ is greater than ‘big’ then ‘b’ will be stored to the resultant variable ‘big’.
- Now, ‘c’ is compared with the resultant variable ‘big’. If ‘c’ is greater than ‘big’ then ‘c’ will be stored to the resultant variable ‘big’.
Below is an example to find greatest of three numbers in C language
printf("\n Enter three numbers: ");
scanf("%d %d %d",&a,&b,&c);
//Here we will assume 'a' is biggest than 'b' and 'c'
big = a;
big = b;
big = c;
printf("\n The greatest of three numbers is: %d",big);
After running the above program, the user has to enter three integer numbers manually and then press ENTER key. When the program is executed, it will display the result as shown below
Enter three numbers: 3 6 9
The greatest of the three numbers is: 9
Process returned 0 (0x0) execution time : 11.593 s
Press any key to continue.
Conclusion:- I hope this tutorial will help you to understand the concept. If there is any doubt then please leave a comment below.
Originally published at https://pbphpsolutions.com on June 27, 2022.