C Program To Find The Smallest Number Using if else

In this article, we are going to write C Program To Find The Smallest Number Using if else

We will 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

To make this program, we will use the following concept given below.

If you do not know about these topics well, then you may not understand this program, so you should know about them in detail from the link given above.

Now without wasting time let’s start programming.

C Program To Find The Smallest Number Using if else

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 Three Numbers 
10
28
12

10 is smallest 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

Conclusion

In this article, we have created all the following programs -:

  • 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

If you have difficulty to understand any program or have any doubts or questions, then tell me in the comment below.

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging

Leave a Comment