w3schools Logo
Monday 21 May 2012
W3schools.in Developer Network
HTML tutorials
CSS tutorials
php tutorials and scripts
MySql tutorials
Learn C Programming
Operating system

c program to find the greatest of three numbers
From w3schools.in

Program:

#include <stdio.h>
int main(){
int a, b, c;
printf("Enter a,b,c: \n");
scanf("%d %d %d", &a, &b, &c);
if (a > b && a > c) {
printf("a is Greater than b and c");
}
else if (b > a && b > c) {
printf("b is Greater than a and c");
}
else if (c > a && c > b) {
printf("c is Greater than a and b");
}
else {
printf("all are equal or any two values are equal");
}
return 0;
}


Output:

Enter a,b,c: 3 5 8
c is Greater than a and b
Explanation with examples:
Consider three numbers a=5,b=4,c=8
if(a>b && a>c) then a is greater than b and c
now check this condition for the three numbers 5,4,8 i.e.
if(5>4 && 5>8) /* 5>4 is true but 5>8 fails */
so the control shifts to else if condition
else if(b>a && b>c) then b is greater than a and c
now checking this condition for 5,4,8 i.e.
else if(4>5 && 4>8) /* both the conditions fail */
now the control shifts to the next else if condition
else if(c>a && c>b) then c is greater than a and b
now checking this condition for 5,4,8 i.e.
else if(8>5 && 8>4) /* both conditions are satisfied */
Thus c is greater than a and b.


This page was last modified on 15 Dec 2011 at 19:37:20.
Gautam Kumar
EDP Manager
http://www.connectsin.com
Related Posts
» C program to display the multiplication table of a given num
» C program to generate the Fibonacci series
» C program to print a semicolon without using a semicolon
» C program to compare two strings without using strcmp
» C program to concatenate two strings without using strcat
» C program to delete a specified line from a text file
» C program to replace a specified line in a text file
» C program to find the number of lines in a text file
» C program which asks the user for a number between 1 to 9
» C program to check whether the given string is a palindrome
» C program to check whether the given number is a palindromic
» C program to find factorial of the given number
» C program to check whether the given number is even or odd
» C program to swap two numbers using a temporary variable
» C program to swap two numbers using bitwise operators
» C program to find the greatest of three numbers
» C program to find the greatest among ten numbers
» C program to check whether the given number is a prime
» How to create pyramid in c
» Fun with C language.