A program for finding smallest number in an array and display their position

Finding smallest number & display their position 



        In this example, we will  understand to find a smallest number in an array and display their position and know how to write, compile and debug it in C language and also learn how to implement it in c.

        
In order to do this you will need
  • Basic knowledge of c programming language.
  • As well as know how to operate codeblocks.   

            An array is a fixed-size sequential collection of  elements of same data types that share a common  name.It is simply a group of data types. An array is a  derived data type.An array is used to represent a list of numbers or  a list of names.


So let's begin with our program

1.Open a codeblocks software.

2.Open new empty file.

3.Copy and paste the code from below. 


A program for finding smallest number in an array and display their position,c programming language,2021,basic codes,input output code



Input code- 

 //Write a program for finding smallest number in an array and display their position.  
   
 #include<stdio.h>  
 int main()  
 {  
   int n[5],i,loc,min;  
   printf("Enter any 5 numbers:\n");  
   for(i=0;i<=4;i++)  
   {  
     scanf("%d",&n[i]);  
   }  
   min=n[0];  
   for(i=0;i<=4;i++)  
   {  
     if(n[i]<min)  
     {  
       min=n[i];  
       loc=i+1;  
     }  
   }  
   printf("Smallest number is %d and is present at location %d",min,loc);  
   return 0;  
 }  
   


Now simply build the code. Look for any error. Now run the code.

For output enter any five number you want and press enter key.



A program for finding smallest number in an array and display their position,c programming language,2021,basic codes,input output code


Click the following button to download a program for finding smallest number in an array and display their position 






Thats it.Thank you for scrolling.



Post a Comment

If you have any doubt or suggestions.please let me know.

Previous Post Next Post

Ads by google

Ads by google