Maximum of an array

 avatar
shebom640
c_cpp
a year ago
514 B
7
Indexable
Never
// write a program to find max of an array

#include <stdio.h>

int main()
{
    int n, i;
    printf("Enter size of an array\n");
    scanf("%d", &n);
    int a[n];
    printf("Enter array elements \n");
    for(i =0; i<n; i++)
    {
        printf("Enter %d element: ", i+1);
        scanf("%d", &a[i]);
    }
    int max = a[0];
    for(i=0; i<n; i++) {
        if(max < a[i])
        {
            max = a[i];
        } else {
            continue;
        }
    }
    printf("Max is %d", max);
    return 0;
}