Search This Blog

Loading...

C Program to find Greatest Number from One Dimensional Array

//Write a program to find greatest number from one dimensional array.
//Code for Program to find greatest number from one dimensional array in C Programming

#include<stdio.h>
#include<conio.h>

int main()
{
    int a[20],n,i,max=0;  // declared the array a with size  20
    clrscr();

    printf("\n Enter  the number of elements for 1-D array : ");
    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
        printf("\n Enter element [%d] : ",i+1);
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(max<a[i])
            max=a[i];
    }

    printf("\n Greatest element from above array inserted is : %d",max);

    getch();

    return 0;
}

Output:
Enter  the number of elements for 1-D array : 5

Enter element [1] : 1
Enter element [2] : 8
Enter element [3] : 2
Enter element [4] : 5
Enter element [5] : 9

Greatest element from above array inserted is: 9

1 comment:

  1. Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

    ReplyDelete