This Post Contains A C++ Program To Find Highest And Lowest Elements Of An Array With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays' & 'For-loop' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.
# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.
C++ Program To Find Highest And Lowest Elements Of An Array.
/* Declaration Of Header Files */
#inlcude<iostream.h>
#include<conio.h>
/* Start Of Main Program */
void main()
{
/* Declaration Of Variables */
int a[20];
int e, dim, highest, lowest;
clrscr();
/* Asking For The Input From User */
cout << " Enter The Dimension Of Array : ";
cin >> dim;
cout << " Now Enter The " << dim << " Elements Into Array : ";
for( e=0; e<dim; e++ )
{
cin >> a[e];
}
/* Source Code For Computing Highest And Lowest Elements Of An Array */
highest=a[0];
lowest=a[0];
for( e=0; e<dim; e++ )
{
if( a[e] > highest )
{
highest = a[e];
}
if( a[e] < lowest )
{
lowest = a[e];
}
}
/* Printing The Output Onto The Screen/Console */
cout << " Highest Element Is : " << highest;
cout << " Lowest Element Is : " << lowest;
getch();
}
/* End Of Main Program */
Output :
Enter The Dimension Of Array : 5
Now Enter The 5 Elements Into Array : 1 2 3 4 5
Highest Element Is : 5
Lowest Element Is : 1
# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.
C++ Program To Find Highest And Lowest Elements Of An Array.
/* Declaration Of Header Files */
#inlcude<iostream.h>
#include<conio.h>
/* Start Of Main Program */
void main()
{
/* Declaration Of Variables */
int a[20];
int e, dim, highest, lowest;
clrscr();
/* Asking For The Input From User */
cout << " Enter The Dimension Of Array : ";
cin >> dim;
cout << " Now Enter The " << dim << " Elements Into Array : ";
for( e=0; e<dim; e++ )
{
cin >> a[e];
}
/* Source Code For Computing Highest And Lowest Elements Of An Array */
highest=a[0];
lowest=a[0];
for( e=0; e<dim; e++ )
{
if( a[e] > highest )
{
highest = a[e];
}
if( a[e] < lowest )
{
lowest = a[e];
}
}
/* Printing The Output Onto The Screen/Console */
cout << " Highest Element Is : " << highest;
cout << " Lowest Element Is : " << lowest;
getch();
}
/* End Of Main Program */
Output :
Enter The Dimension Of Array : 5
Now Enter The 5 Elements Into Array : 1 2 3 4 5
Highest Element Is : 5
Lowest Element Is : 1
No comments:
Post a Comment