Q:

C Program To Find Largest of Two Numbers

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following way:

  1. C Program To Find Largest of Two Numbers Using if statement
  2. C Program To Find Largest of Two Numbers Using Function
  3. C Program To Find Largest of Two 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 Two Numbers (Simple Way)

Algorithm -:

  1. Program Start
  2. Declaration of Variables
  3. Input Two number
  4. Check the condition
  5. Display answer according the condition
  6. Program End

Program -:

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

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

   printf("Enter Two Numbers\n");
   scanf("%d %d",&a,&b);

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

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

}

Output -:

Enter Two Numbers
39
49

Largest Number is : 45

 

C Program To Find Largest of Two Numbers Using Function

Algorithm -:

  1. Program Start
  2. Declaration of Variables
  3. Input Two number
  4. Calling Function to find Largest Number
  5. Check the condition
  6. Display answer according the condition
  7. Program End

Program -:

//C Program To Find Largest of Two Numbers Using Function

#include<stdio.h>
void largest(int a, int b)
{
   int larg;
  
 if(a>b)  // larg among a and b
  {
    larg = a;
  }
  else
  {
    larg = b;
  }

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

}
void main()
{
  // Variable declaration
   int a,b;

   printf("Enter Two Numbers\n");
   scanf("%d %d",&a,&b);
   largest(a,b);
}

Output -:

Enter Two Numbers
3
9

Largest Number is : 9

 

C Program To Find Largest of Two Numbers Using Conditional Operator

Program -:

//C Program To Find Largest of Two Numbers Using Conditional Operator

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

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

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

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

}

Output -:

Enter Two Numbers
93
47

Largest Number is : 93

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 of Three Numbers ( 3 Dif... >>
<< C Program To Find Smallest of Three Numbers...