Monday, June 18, 2012

To find the largest number in the array


/* Program to find the largest number in the array */

#include<stdio.h>

#include<conio.h>

void main()

{

  int arr[10],i,large;

  clrscr();

  /* To enter elements in a 1-D array */

  printf("Enter the elements of the array:\n");

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

  {

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

  }

  large=arr[0];

  /* To search for the largest element */

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

  {

    if(arr[i] > large)

    {

      large = arr[i];

    }

  }

  printf("\nLargest element in the array=%d",large);

  getch();

}

 

OUTPUT

Enter the elements of the array:

24

38

72

18

64

98

34

88

64

36

 

Largest element in the array=98

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.