Q:

C Program To Find Smallest of Three Numbers

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following ways:

  • C Program to find Smallest of Three numbers (Simple Way)
  • C Program to find Smallest of Three numbers using function
  • C Program to find Smallest of Three numbers using conditional operator
  • C Program to find Smallest of n numbers using for loop

All Answers

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

C Program To Find Smallest of Three Numbers Using ( Simple Way )

Algorithm -:

  1. Program Start
  2. Variable Declaration
  3. Input three number
  4. Check the condition
  5. Display answer according the condition
  6. Program End

Program -:

//C program to find Smallest among three numbers 

#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("Smallest Number is : %d",small);

}

Output -:

Enter Three Numbers
12
43
28

Smallest Number is : 12

 

C Program To Find Smallest of Three Numbers Using Function

Algorithm -:

  1. Program Start
  2. Variable Declaration
  3. Input three number
  4. Calling Function to find Smallest Numbers among Three number
  5. Check the condition
  6. Display answer according the condition
  7. Program End

Program -:

//C program to find Smallest among three numbers Using Function

#include<stdio.h>
void small(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 smallest number
   small(a,b,c);
}
void small(int a, int b, int c)
{  int small;
     // 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("Smallest Number is : %d",small);

}

Output -:

Enter Three Number
32
23
43

Smallest Number is : 23

 

C Program To Find Smallest of Three Numbers Using Conditional OR Ternary Operator

Algorithm -:

  1. Program Start
  2. Variable Declaration
  3. Input three number
  4. Check the condition
  5. Display answer according the condition
  6. Program End

Program -:

//C program to find Smallest among three numbers using Conditional operator 

#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
   small = a<b?a<c?a:c:b<c?b:c;

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

}

Output -:

Enter Three Number 
10
20
11

Smallest Number is : 10

 

C Program To find Smallest of n Number Using For Loop

Algorithm -:

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

Program -:

//C Program To find Smallest of n Number Using For Loop

#include<stdio.h>
void  main()
{
    int i,n,a[100],small;

    printf("Enter How many number you want?:\n") ;
    scanf("%d",&n) ;

    printf("Enter %d numbers\n",n) ;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]) ;
    }

    small=a[0];
    for(i=1;i<n;i++)
    {
        if(a[i]<small)
        {
            small=a[i];
        }
    }
    printf("Smallest Number is : %d",small);
}

Output -:

Enter How many number you want?
5
Enter 5 number
12
134
31
23
322

Smallest Number is : 12

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 Two Numbers... >>
<< C Program to Find the Sum and Average of n Numbers...