codescracker


c++

C++ Program to Find Smallest Element in Array



« Previous Program Next Program »


Find Smallest Element in Array in C++

To find the smallest element in an array in C++ programming, you have to ask to the user to enter the array size and array elements, now start finding for the smallest element in the array to display the smallest element of the array as shown here in the following program.

C++ Programming Code to Find Smallest Element in Array

Following C++ program ask to the user to enter array size and array elements to find the smallest element present in the array, then display the result on the screen:

C++ Programming Example Source Code:
/* C++ Program - Find Smallest Element in Array */
		 
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int small, arr[50], size, i;
	cout<<"Enter Array Size (max 50) : ";
	cin>>size;
	cout<<"Enter array elements : ";
	for(i=0; i<size; i++)
	{
		cin>>arr[i];
	}
	cout<<"Searching for smallest element ...\n\n";
	small=arr[0];
	for(i=0; i<size; i++)
	{
		if(small>arr[i])
		{
			small=arr[i];
		}
	}
	cout<<"Smallest Element = "<<small;
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program find smallest element in array

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test