Q:

C Program To Find Largest of Three Numbers ( 3 Different Ways )

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following way:

  • C Program to find Largest of Three numbers (Simple Way)
  • C Program to find Largest of Three numbers using function
  • C Program to find Largest of Three numbers using conditional operator

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C Program To Find Largest of Three Numbers (Simple Way)

Program -:

//C Program To Find Largest of Three Numbers (Simple Way)

#include<stdio.h>
void main()
{
  // Variable declaration
   int a,b,c, larg;

   printf("Enter Three Number\n");
   scanf("%d %d %d",&a,&b,&c);

  // larg among a, b and c
  if(a>b)
  {
      if(a>c)
        larg = a;
      else
        larg = c;
  }
  else
  {
      if(b>c)
        larg = b;
      else
        larg = c;
  }

  //Display Largest number
    printf("Largest Number is : %d",larg);

}

Output -:

Enter Three Number
49
27
38
Largest Number is : 49

 

C Program To Find Largest of Three Numbers Using Function

Program -:

#include<stdio.h>
void larg(int, int, int);
void main()
{
  // Variable declaration
   int a,b,c;

   printf("Enter Three Number\n");
   scanf("%d %d %d",&a,&b,&c);

   //calling function to find largest number
   larg(a,b,c);
}
void larg(int a, int b, int c)
{  int larg;
     // larg among a, b and c
  if(a>b)
  {
      if(a>c)
        larg = a;
      else
        larg = c;
  }
  else
  {
      if(b>c)
        larg = b;
      else
        larg = c;
  }

  //Display Largest number
    printf("Largest Number is : %d",larg);

}

Output -:

Enter Three Nuumbers
39
33
31

Largest Number is : 39

 

C Program To Find Largest of Three Numbers Using Conditional Operator

Program -:

//C program to find Largest number among three numbers using Conditional operator

#include<stdio.h>
void main()
{
  // Variable declaration
   int a,b,c,larg;

   printf("Enter Three Number\n");
   scanf("%d %d %d",&a,&b,&c);

  // Larg among a, b and c
   larg = a>b?a>c?a:c:b>c?b:c;

  //Display Largest number
   printf("Largest Number Among 3 Number : %d",larg);

}

Output -:

Enter Three Nuumbers
329
323
328

Largest Number Among 3 Numbers : 329

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Basic C Programming Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program To Find Largest And Smallest of Three Nu... >>
<< C Program To Find Largest of Two Numbers...