Monday, March 27, 2017

write a program that will show the max value in an array using function

#include<stdio.h>
void maximum(int array[],int i)
{

    int max = array[0];///3

    int min = array[0];///3


    for(i=1;i<5;i++)
    {
        if(array[i]>max)
        {
            max = array[i];///max = 3, 4 ,6 ,8

        }
        else if(array[i]<min)
        {
            min = array[i];
        }
    }
    printf("maximum = %d\n",max);
    printf("minimum = %d\n",min);

}

main()
{
    int array[]={3,40,2,6,8},i;
    maximum(array,i);


}

No comments:

Post a Comment