Search This Blog

Showing posts with label biggest of 3 numbers. Show all posts
Showing posts with label biggest of 3 numbers. Show all posts

31 May, 2011

C Program of finding biggest of 3 numbers using ternary operator.


/* Biggest of 3 numbers using ternary operator - BIGTER.C */

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c, big;
clrscr();
a=1;
printf("Enter three numbers: ");
scanf("%d %d %d",&a, &b, &c);
big = a > b ? (a>c?a:c):(b>c?b:c);
printf("\nThe biggest number is : %d",big);
getch();


}


RUN 1 :
~~~~~~~
Enter three numbers : 10 20 30
The biggest number is : 30
RUN 2 :
~~~~~~~
Enter three numbers : 20 30 10
The biggest number is : 30
RUN 3 :
~~~~~~~
Enter three numbers : 30 10 20
The biggest number is : 30

C- Program to find the biggest of three numbers.


/* Finding the biggest of 3 numbers using if...else - BIGIFEL.C */

# 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() ;
}
RUN 1 :
~~~~~~~
Enter three numbers : 10 20 30
30 is the biggest number
RUN 2 :
~~~~~~~
Enter three numbers : 20 30 10
30 is the biggest number
RUN 3 :
~~~~~~~
Enter three numbers : 30 10 20
30 is the biggest number

Meetme@