Q:

C Program To Find The Smallest Number Using if else

belongs to collection: If Else Programs in C

0

you have to make this program in the following way:

  • C Program To Find The Smallest of 2 Numbers Using If Else
  • C Program To Find The Smallest of 3 Numbers Using If Else
  • C Program To Find The Smallest of 4 Numbers Using If Else
  • C Program To Find The Smallest of 5 Numbers Using If Else

All Answers

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

C Program To Find The Smallest of 2 Numbers Using if else

Algorithm -:

  1. Program Start
  2. Declare Variables
  3. Input Two numbers
  4. Check the condition
  5. Display answer according the condition
  6. Program End

Program -:

//C program to find Smallest of two numbers Using If Else

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

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

  // Small among a and b
    if(a<b)
      {
          small = a;
      }
    else
      {
          small = b;
      }

  //Display smallest number
    printf("%d is smallest number",small);
    
    return 0;
}

Output -:

Enter Two Numbers
10
29

10 is smllest number

C Program To Find The Smallest of 3 Numbers Using if else

Algorithm -:

  1. Program Start
  2. Declare Variables
  3. Input three number From User
  4. Check the condition
  5. Display answer according the condition
  6. Program End

Program -:

//C program to find Smallest among three numbers Using if else 

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

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

  // Small among a, b and c
  if(a<b)
  {
      if(a<c)
        small = a;
      else
        small = c;
  }
  else
  {
      if(b<c)
        small = b;
      else
        small = c;
  }

//Display smallest number
 printf("%d is smallest number",small);

return 0;
}

Output -:

Enter Two Numbers
10
29

10 is smllest number

C Program To Find The Smallest of 4 Numbers Using if else

Program -:

//C program to find Smallest of four numbers Using If Else

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

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

  // Small among a, b, c and d
    if(a<b)
      {  if(a<c)
          {
              if(a<d)
              {
                  small = a;
              }
              else
              {
                  small = d;
              }
          }
          else
          {  if(c<d)
              small = c;
             else
              small = d;
          }
      }
    else
      { if(b<c)
           {
               if(b<d)
               {
                small = b;
               }
               else
               {
                small = d;
               }
           }
           else
           { if(c<d)
               {
                small = c;
               }
              else
              {
                small = d;
              }
           }

      }

  //Display smallest number
    printf("%d is Smallest Number",small);

    return 0;
}

Output -:

Enter Four Numbers
10
28
19
7

7 is smallest number

C Program To Find The Smallest of 5 Numbers Using if else

Program -:

//C program to find Smallest of five numbers Using If Else

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

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

  // Small among a, b, c, d and e
    if(a<b)
      {  if(a<c)
          {
              if(a<d)
              {
                if(a<e)
                  small = a;
                else
                  small = e;
              }
              else
              {
                  if(d<e)
                    small = d;
                   else
                    small = e;
              }

          }
          else
          {  if(c<d)
               {
                    if(c<e)
                        small = c;
                    else
                        small = e;
               }
             else
             {
                 if(d<e)
                    small = d;
                 else
                    small = e;
             }

            }
      }
    else
      { if(b<c)
           {
               if(b<d)
               { if(b<e)
                   small = b;
                 else
                    small = e;
               }
               else
               { if(d<e)
                   small = d;
                 else
                    small = e;
               }
           }
           else
           { if(c<d)
               { if(c<e)
                   small = c;
                 else
                   small = e;
               }
              else
              { if(d<e)
                   small = d;
                else
                   small = e;
              }
           }
      }

  //Display smallest number
    printf("%d is Smallest Number",small);

    return 0;
}

Output -:

Enter five numbers
19
29
18
27
13

13 is smallest number

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

total answers (1)

<< Enter Temperature in Celsius : 37 Enter Temperatu...