43 : C Program to Find Smallest among 3 numbers

Check out the complete list of c-programs : C Program List    



Find the Greatest number among the 3 entered numbers.

Variables :

n1,n2 and n3 : Datatype int : Holds value of number1, number2 and number3 inputted by the user.

smallest_no : Datatype int : To hold the smallest values.

temp : Datatype int : To hold temporary values.



Logic :


    if (n1 < n2)
    {
        if (n1 < n3) { 
            
            smallest_no = n1;
            
        }
        
        else {
            
             smallest_no = n3;
             
        }
    }

  else  if (n2 < n3) {
        
        smallest_no =  n2;
        
    }
    else 
     {
       smallest_no = n3;
     }





/*
 * 1000+ C programs + tutorials
 *
 * 
 * 43_find_smallest_number_amoung_3.c
 *
 *
 *  Created on: Oct 20, 2014
 *  Author: Code2care.org
 */

#include 
//#include 



void main() {

   int n1,n2,n3;
   int smallest_no;
   int temp;
  

//    clrscr();

    printf("C Program to Find Smallest Number amound 3 Entered Number");

    printf("\n\n Enter Number 1: ");
    scanf("%i", &n1);
    
    printf("\n\n Enter Number 2: ");
    scanf("%i", &n2);
    
     printf("\n\n Enter Number 3: ");
    scanf("%i", &n3);
    

     
     
   //Logic to find Smallest Number
   

  
    if (n1 < n2)
    {
        if (n1 < n3) { 
            
            smallest_no = n1;
            
        }
        
        else {
            
             smallest_no = n3;
             
        }
    }

  else  if (n2 < n3) {
        
        smallest_no =  n2;
        
    }
    else 
     {
       smallest_no = n3;
     }
   
   
   printf("\n\n Smallest Among Numbers %i,%i and %i : %i",n1,n2,n3, smallest_no);
    
  



//	getch();



}










The best way to learn C programming is to practice more and more of programs . Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.

BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.