This C Program calculates the biggest of 3 numbers.The program assumes 3
numbers as a, b, c. First it compares any 2 numbers check which is
bigger. After that it compares the biggest element with the remaining
number. Now the number which is greater becomes your biggest of 3
numbers.
Here is source code of the C program to calculate the biggest of 3
numbers. The C program is successfully compiled and run on a Linux
system. The program output is also shown below.
/*
* C program to find the biggest of three numbers
*/
#include <stdio.h>
void main()
{
int num1, num2, num3;
printf("Enter the values of num1, num2 and num3\n");
scanf("%d %d %d", &num1, &num2, &num3);
printf("num1 = %d\tnum2 = %d\tnum3 = %d\n", num1, num2, num3);
if (num1 > num2)
{
if (num1 > num3)
{
printf("num1 is the greatest among three \n");
}
else
{
printf("num3 is the greatest among three \n");
}
}
else if (num2 > num3)
printf("num2 is the greatest among three \n");
else
printf("num3 is the greatest among three \n");
}
$ cc pgm6.c $ a.out Enter the values of num1, num2 and num3 6 8 10 num1 = 6 num2 = 8 num3 = 10 num3 is the greatest among three
No comments:
Post a Comment