Monday, December 13, 2010

Program to find the greatest number using pointers

#include<stdio.h>

void main()
{
    int a[20],i,*p,x,*y,n;
    printf("How many numbers?");
    scanf("%d",&n);
    p=a;
    y=&x;
    printf("Enter %d numbers:",n);
    for(i=0;i<n;i++)
    {
        scanf("%d",(p+i));
    }
    *y=*p;
    for(i=0;i<n;i++)
    {
        if(*y<*(p+i))
        *y=*(p+i);
    }
    printf("\n The greatest number is %d.",x);
}

No comments:

Post a Comment