Greatest of thee numbers

WE will ask user to enter three numbers. We will store then in three variables and then compare with each other by using if else conditional statement.
Here is the sample code.
#include <stdio.h>
int main(void){
int a,b,c;
	printf("Enter the  number ");
scanf("%d %d %d",&a,&b,&c);  // Enter  numbers

if(a>b){
 if(a > c )
 { printf(" Highest number is a = %d",a);}
 else
 { printf(" Highest number is c = %d",c);}
}
else
{
 if(b > c )
 { printf( "highest number is b = %d",b);}
 else
 {printf(" highest number is c= %d",c);}
}
	return 0;
}

Solution using AND ( && ) logical conditions

#include <stdio.h>
int main(void){
int a,b,c;
	printf("Enter the  number ");
scanf("%d %d %d",&a,&b,&c);  // Enter  numbers
if(a>b && a>c){
  printf("Greatest number is a: %d",a);
}else if(b>c && b>a){
  printf("Greatest number is b: %d",b);
}else if (c>a && c>b){
printf("Greatest number is C: %d",c);
}
return 0;
}
Your Rating




Post your comments , suggestion , error , requirements etc here




HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer