Sum of max and min element of array data structure by R4R Team

Example-
Array is [2,1,0,9,4,5,3]
Sum of max and min is 9+0=9

program-

#include< stdio.h>
int main()
{
int a[20],n,i,max,min;
printf("Enter number of elements in arary\n");
scanf("%d",&n);
printf("Enter %d number in array",n);
for(i=0;i< n;i++)
scanf("%d",&a[i]);
//find maximum
max=a[0];
for(i=0;i< n;i++){
if(a[i]>max)
{
max=a[i];
}
}
//find minimum
min=a[0];
for(i=0;i< n;i++){
if(a[i]< min)
{
min=a[i];
}
}
printf("Sum of max and min value is %d",max+min);
}


output-

Enter number of elements in array
8
Enter 8 number in array
3 2 1 4 5 6 7 8
Sum of max and min value of array is 9

-In this program, Firstly we take an input in array
-Then we run two loops , one for finding the max element and another for finding the min element.
-When we have both max and min, then we add both value and display on console.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!