Subscribe

RSS Feed (xml)

Friday, June 19, 2009

Write a C program to find the greatest number between four numbers using if-else ladder

#include(stdio.h)
#include(conio.h)
int main( )
{
int a, b, c, d;
clrscr( );
printf("Enter the four different numbers:")l
scanf(" %d %d %d %d", &a, &b, &c, &d);
if(a>b && a>c && a>d)
printf("\n%d is greatest", a);
else if(b>a && b>c && b>d)
printf("\n%d is greatest", b);
else if(c>a && c>b && c>d)
printf("\n%d is greatest", c);
else
printf("\n %d is greatest", d);
getch( );
}
Note:- if u have any doubts regarding this program, feel free to contact my email id

9 comments:

  1. pls help me 2 write it simply using conditional operator without using an xtra variable.I'm only at d footsteps of c++.pls get it as soon as possibl.

    ReplyDelete
  2. if program above written without using if condition then

    ReplyDelete
  3. pls help me 2 write it simply using conditional operator without using an xtra variable.

    ReplyDelete
  4. thank U was helpful

    ReplyDelete
  5. 5 7 7 5 output shows wrong

    ReplyDelete
  6. int m;
    m=(a>b && a>c && a>d ) ? a: ((b>c && b>d) ? b : ((c>d)?c : d));
    printf("%d",m);
    // m is the greatest

    ReplyDelete