Here's a program to find the biggest of 3 numbers using if...else with output and explanation in C programming language.
# include <stdio.h> # include <conio.h> void main() { int a, b, c ; clrscr() ; printf("Enter three numbers : ") ; scanf("%d %d %d", &a, &b, &c) ; if(a > b) { if(a > c) printf("\n%d is the biggest number", a) ; else printf("\n%d is the biggest number", c) ; } else { if(c > b) printf("\n%d is the biggest number", c) ; else printf("\n%d is the biggest number", b) ; } getch() ; }
Output of above program
Enter three numbers : 5 15 2
15 is the biggest number
Explanation of above program
First we ask user to enter three numbers and store them respectively in a, b, c variables. Next we have an if else condition which determines which of the three numbers is the biggest. Lets understand how it works.
- If a > b, then we check if a is also greater then c and if a > c then a is the biggest number.But if a < c in this case then c is the biggest of a, b and c.
- If a < b then else part is executed. Then we check if c > b and if it is then c is the biggest number. Otherwise b is the biggest number of three.
Tip: If you want to find the smallest number of 3 numbers simply change greater than ( > ) ti less than ( < ).
what if a == b............
i mean this thing does not work.......when i enter the integers as follows:
5
5
13
@Killed By Death: Sorry for the late reply but this code works just fine even when two or all the three numbers are same.
If you notice in the first IF we are checking for a > b so the ELSE part is dealing with a <= b.
So, in your example when a = b = 5 and c = 13, the condition a > b is false so the ELSE part is executed. Then inside ELSE, the first IF is executed as c > b (13 > 5). So the output of the program is "13 is the biggest number". Hope this explanation clears your doubt.
We can include above
else if(a==b)&&(a>c)
Hello Mate,
I learnt so much in such little time about Program to Find the Biggest of 3 Numbers Using if else in C. Even a toddler could become smart reading of your amazing articles.
Could someone explain this code step by step:
Code:
#include
#define MAX 10
int main()
{
char array[MAX][MAX], c = 0;
int d = 1, x = 0, i, j;
do scanf("%s", array[x]);
while (array[x++][0] != '0');
{
float* pf;
int xx, *pi = (int*)&array[0][7];
xx = ((*pi) & 0x41000000);
pf = (float*)&xx;
printf("%5.2f\n", *pf);
}
for (c-=--x; c++&**array; d+=!(c<0)) d<<=1;
d -= c;
for (i = 0; i < x;
i==1?printf("%c ", array[i][x>>1]):i, ++i)
for (j = 0; j <= x - i;
printf("%c", array[i][j++]));
printf("%x", d);
return 0;
}
By the way do you have any YouTube videos, would love to watch it. I would like to connect you on LinkedIn, great to have experts like you in my connection (In case, if you don’t have any issues).
Best Regards,
Irene Hynes