#include<conio.h>
#include<stdio.h>
main()
{
int a,b,c;
clrscr();
printf("enter your first value:");
scanf("%d",&a);
printf("enter your second value:");
scanf("%d",&b);
printf("enter your third value:");
scanf("%d",c);
    if(a>b && a>c)
    {
       printf("first value is greater");
    }
    else if(b>a&&b>c)
    {
    printf("2nd value is greater");
    }
    else if(c>a&&c>b)
    {
    printf("third value is greater");
    }
getch();

Code runs successfully but it shows wrong output
for example i enter
a=30
b=29
c=28
it output" third value is greater"

Please help

Recommended Answers

All 2 Replies

You are missing an & in the third scanf. Try to make this correction. Also use code tags next time you post code. Thanks.
EDIT
You should also use int main() and set a return value of zero.

instead of checking
if(a>b && a>c)
if(b>a && b>c)
if(c>b && c>a)

you could use

void find_big( int, int, int, int* );
int main()
{
   int a,b,c;
   int big; 
   printf("Enter three values\n");
   scanf("%d%d%d",&a,&b,&c);
   find_big(a,b,c,&big);
   printf("Big=%d\n",big);
   return 0;
}  

void find_big(int a , int b, int c ,int *big); 
{
     if(a>b)
     {
        if(a>c)
                 *big=a;            
        else
                 *big=c;
     }
   else
  {
      if(b>c)
            *big=b;
      else
           *big=c ;
  }
}

in that case either if or else is executed

or else
in a single line you could do this
int main() {
int a=23, b=15, c=8;
int big =( a >b ? (a > c ? a : c) : (b > c ? b : c) );
printf("Big= %d",big);
return 0;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.