find the sum of largest and smallest number in an array in c program
Question
find the sum of largest and smallest number in an array in c program
in progress
0
Mathematics
11 months
2021-06-22T06:14:12+00:00
2021-06-22T06:14:12+00:00 1 Answers
0 views
0
Answers ( )
Answer:
#include<stdio.h>
int main()
{
int a[10],I,n,large,small;
print(“\n Enter the number of elements : “);
scanf(“%d”,&n);
print(“\n Input the array elements : “);
for( i=0;i<n;++i)
scanf (“%d”,&a[i]);
large=small=a[0];
for(i=1;i<n;++i)
{
if (a[i]>large)
large=a[i];
if(a[i]<small)
small=a[i];
}
printf (“\n the smallest element Is %d\n”,small);
printf(“\n The largest element is %d\n”,large);
return 0;
}
OUTPUT :
Enter the number of elements : 3
Input the array elements : 2 4 6
The smallest element is : 2
The largest element is : 6