Solved programming problem

How to find the maximum value in 1D array.

Source code

#include<stdio.h>

int main()

{

    int array[100];/// declare a 1D Array.

    int i,n,max;

    printf("
Please Enter The array size:");

    scanf("%d",&n);

    printf("
Please Enter %d Element Of the array: 
",n);

    for(i=0; i<n; i++) ///scan array element

    {

        scanf("%d",&array[i]);

    }

    max=array[0];///Set the 1st element as maximum value.

    for(i=0; i<n; i++)

    {

        if(array[i]>max)///checking if any number is gather then or not

        {

            max=array[i];///if found,replace that.

        }

    }

    printf("
The max value is: %d
",max);

    return 0;

}

Output

Please Enter The array size:5

Please Enter 5 Element Of the array:

1 -8 4 78 0

The max value is:  78

Join the discussion

Add your comment