Pages

100 Contemporary Living Room Designs

Wednesday, August 8, 2012

LARGEST IN AN ARRAY

Program to find the largest number in an array using pass by address and array passing.


#include<iostream.h>
#include<conio.h>
void large(int a[],int *n);
void main()
{
  int x[10],i,l;
  clrscr();
  cout<<"Enter ten numbers\n";
  for(i=0;i<10;i++)
  {
    cin>>x[i];
  }
  large(x,&l);
  cout<<"Largest number is "<<l;
  getch();
}
void large(int a[],int *n)
{
  int i;
  *n=a[0];
  for(i=0;i<10;i++)
  {
    if(a[i]>*n)
    {
      *n=a[i];
    }
  }
}

Output



No comments:

Post a Comment