Write a C program to check largest among n digits?

#include<stdio.h>
#include<conio.h>
int max(int a[], int n);
void main()
{
    int largest, i, n, a[100];
    printf("Enter length of n numbers: ");
    scanf("%d",&n);
    printf("Enter the numbers: ");
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    largest=max(a,n);
    printf("The largest number is %d",largest);
    getch();
}
int max(int a[], int n)
{
    int i, m=0;
    for(i=0; i<n; i++)
    {
        if(a[i]>m)
        m = a[i];
    }
    return m;
}

Output:


Comments

Popular posts from this blog

Larch Soft Pvt. Ltd. - Best Website & Hosting Provider