Find Maximum and Minimum and Summation value from array

Did this problem from subeen vai’s book.

For maximum value:

#include<stdio.h>
int find_max(int ara[],int n);
int main()
{
 
    int ara[]={-100,0,53,22,83,23,89,-132,201,3,85};
    int n=11;
    int max=find_max(ara,n);
    printf("%d\n",max);
    return 0;
}
 
int find_max(int ara[],int n)
{
    int max=ara[0]; //assume that first value of array according to index is maximum we will compare later with this
    int i;
    for(i=1;i<n;i++)
    {
        if(ara[i]>max) //here it is iterating the whole array
        {
            max=ara[i];
        }
    }
 
    return max;
}

For minimum value:

#include<stdio.h>
int find_min(int array[],int n);

int main()
{
    int array[]= {20,10,-123,980,60,50,70};
    int n=7;
    int min;
    min=find_min(array,n);
    printf("%d\n",min);
    return 0;
}

int find_min(int array[],int n)
{
    int min=array[0];
    int i;
    for(i=0; i<n; i++)
    {
        if(array[i]<min)
        {
            min=array[i];
        }
    }
    return min;
}

Summation:

#include<stdio.h>
int find_sum(int ary[],int valu);
int main()
{
    int ary[]={10,20,30};
    int n=3;
    int sum;
    sum=find_sum(ary,n);
    printf("%d\n",sum);
    return 0;
}
 
int find_sum(int ary[],int n)
{
    int i;
    int sum=0;
    for(i=0;i<n;i++)
    {
        sum=sum+ary[i];
    }
return sum;
}

Average:

Will give here

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *