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 Turbo C/C++3.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<stdio.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 */
printf(" \n Enter The Dimension Of Array : ");
scanf("%d", &dim);
printf(" \n Now Enter The %d Elements Into Array : ", dim);
for( e=0; e<dim; e++ )
{
scanf("%d", &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 */
printf(" \n Highest Element Is : ", highest);
printf(" \n 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<stdio.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 */
printf(" \n Enter The Dimension Of Array : ");
scanf("%d", &dim);
printf(" \n Now Enter The %d Elements Into Array : ", dim);
for( e=0; e<dim; e++ )
{
scanf("%d", &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 */
printf(" \n Highest Element Is : ", highest);
printf(" \n 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