Tuesday, 31 May 2011

Which Number is Largest? / Array

#define MAXSIZE 20
int max(int[], int);
void main()
{
 int list[MAXSIZE];
 int size=0;
 int num;
 do
  {
   printf("Type number: ");
   scanf("%d",list[size]);
  }
 while(list[size++] != 0);
 num=max(list,size-1);
 printf("Largest Number is %d",num);
}
int max(int list[],int size)
{
  int dex,max;
  max = list[0];
  for(dex=1;dex<size;dex++)
   if(max < list[dex])
    max = list[dex];
  return(max);
}


Output:


Type Number: 42
Type Number: 1
Type Number: 64
Type Number: 33
Type Number: 27
Type Number: 0 
Largest Number is 64



0 comments:

Post a Comment