Write a c program to find largest among three numbers using conditional operator






Write a c program to find largest among three numbers using conditional operator


#include<stdio.h>
int main(){
  int a,b,c,big;
  printf("\nEnter 3 numbers:");
  scanf("%d %d %d",&a,&b,&c);

  big=(a>b&&a>c?a:b>c?b:c);
  printf("\nThe biggest number is: %d",big);

  return 0;
}



If you have any suggestions on above c program to find largest or biggest of 3 numbers, please share us.





27 comments:

Saranya said...

Excellent piece of code :) Thanks a lot

ANAND PRAKASH said...

Thanks for solving many problem related to any programming problem issue....

punitpannu said...

#include
int main(){
int a,b,c,big;
printf("\nEnter 3 numbers:");
scanf("%d %d %d",&a,&b,&c);
big=(a>b?(a>c?a:b):(b>c?b:c));
printf("\nThe biggest number is:%d",big);
return 0;
}


wanaa any help regarding C..jst mail me at
gotopunit@gmail.com

Baldev said...

any idea how to do this:


Write a program that requests 5 numbers from the user then finds the minimum number among all the number.

Sample Input:
Enter a number 1: 3
Enter a number 2: 0
Enter a number 3: -4
Enter a number 4: 9
Enter a number 5: 0

Sample Output:
Numbers you had input are: 3 0 -4 9 0
Minimum number is: -4

Anonymous said...

#include
#include
#define size 5
void main()
{
int no[size],min=0,max=0,i;
clrscr();
for(i=0;ino[i])
{
min=no[i];
}
if(max<no[i])
{
max=no[i];
}
}
printf("\n Minimum No is : - %d",min);
printf("\n Maximum No is : - %d",max);
getch();
}

Note : you can find minimum and maximum number from any number of input number.

Anonymous said...

void main()
{
int no[5],i,min,max;
clrscr();
for(i=0;i<5;i++)
{
printf("\n Enter %d No : - ",i+1);
scanf("%d",&no[i]);
}
min=max=no[i];
for(i=0;i<5;i++)
{
if(min>no[i])
min=no[i];
if(max<no[i])
max=no[i]
}
printf("\n Minimum No is : - %d",min);
printf("\n Maximum No is : - %d",max);
getch();
}

amit sahay said...

#include
#include
int main()
{
int a,b,c;
printf("Enter value of a,b,c\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("Largest no is\t%d",a);
else
printf("Largest no is\t%d",c);
}
else
{
if(b>c)
printf("Largest no is\t%d",b);
else
printf("Largest no is\t%d",c);
}
getch();
}

Hussnain Javed said...

I wanna Calculate Biggest number among 5 integers plz help me


Anonymous said...

pls explain me the 6th line of the above prog...

ritesh kumar said...

6th line: a>b&&a>c?a:b>c?b:c

It is equivalent to:
if(a > b && a>c)
return a
else if (b>c)
return b
else
return c

Anonymous said...

nice explanation

Anonymous said...

thanks for the help and explanation

Anonymous said...

Please show me a program which Takes 10 integers as input and prints the largest one.

Anonymous said...

Write a c program that allows the user to input an integer value n, followed by n floating point numbers and display the sum of these n values as well as the largest and smallest among the values.

Anonymous said...

then how to find the smallest

Anonymous said...

biggest of 3 nos program is correct.. got correct output ........ but we enter 8-3-9 getting "3 is a largest no" (or) if we enter this no 6-5-9 also getting "5 is largest no" ......... how is possible pls give a solution for me
...............by raghu

Akshay Kumar singh said...

Your solution is wrong the correct expression of line no. 6 will be :

big = (a>b)?(a>c?a:c):(b>c?b:c);

amit bhardwaj said...

This code is wrong Try new code .

Ramagiri Sanjay said...

#include
#include
#define size 5
void main()
{
int no[size],min=0,max=0,i;
clrscr();
for(i=0;ino[i])
{
min=no[i];
}
if(max<no[i])
{
max=no[i];
}
}
printf("\n Minimum No is : - %d",min);
printf("\n Maximum No is : - %d",max);
getch();
}

Vishal Yevale said...

its a very good sir . . .

Shine Riya said...

write a prg to input 3 no and print the largest no using conditional statement

usman khan said...

plargest of 3 numbers using conditional statements...,

usman khan said...

largest of 3 numbers using conditional statement

#include
void main()
{

int a,b,c;

printf("enter values of a,b and c");
scanf(" %d %d %d",&a,&b,&c);

if(a>b && a>c)
{ printf(" %d is greater",a); }

else if(b>c)
{ printf(" %d is greater",b); }

else
printf(" %d is greater",c);

}

Aakash Mahajan said...

program to display greatest of four numbers

mounika gopisetty said...

// largest of 5 no.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include
#include


int _tmain(int argc, _TCHAR* argv[])
{
int a[5],i,n,small,large;
printf("enter array size\n");
scanf("%d",&n);
for(i=0;ia[i])
{
small=a[i];
}
if(large<a[i])
large=a[i];
}
printf("small no=%d",small);
printf("large=%d",large);
getch();
return 0;
}

Download variety of e-books for just a token said...

Please I need a code that determines if two is less than five using a ternary operator

Shahidul Islam said...

#include
int main(){
int a,b,c;
printf("enter the value of a b c:");
scanf("%d %d %d",&a,&b,&c);
if (a>b && a>c)
{
printf (“The largest number is a:%d”,a);
}
else if (b>a && b>c)
{
printf (“The largest number is b:%d”,b);
}
else
{
printf (“The largest number is c:%d”,c);
}
return 0;
}