Tuesday, August 30, 2011

C Program to find the biggest and smallest number in an array using pointers

#include<stdio.h>
#include<conio.h>
void main()
{
  int a[20],i,d;
  int *ptr,*big=0;
  clrscr();
  printf(" \n Enter dimension : ");
  scanf("%d",&d);
  printf(" \n Enter %d values : ",d);
     for(i=0;i<d;i++)
     scanf("%d",&a[i]);
     ptr=a;

     for(i=0;i<d;i++)
     {
        if(*big < *ptr)
        *big=*ptr;
            if(*low<*ptr)
            *low=*ptr;
         ptr++;
     }
     printf("\n Elements of Array a : \n");
     for(i=0;i<d;i++)
     printf("%d\t",a[i]);
     printf("\n The biggest value Of ARRAy : %d",*big);
     printf("\n The lowest value of  ARRAy : %d",*low);
     getch();
}

4 comments:

  1. Replies
    1. check the modified code... hope it will help you...

      Delete
  2. hey, it will be work just a little bit of modification to be done. try this code, it works...
    #include
    #include
    void main()
    {
    int a[10],i,n,*p,low,high;
    clrscr();
    printf("\nenter the size");
    scanf("%d",&n);
    for(i=0;ihigh)high=*p;
    p++;
    }
    printf("largest is %d, smallest is %d",high,low);
    getch();

    }

    ReplyDelete
  3. it not working is shows the value of any unknown address or garbej value

    ReplyDelete