Wednesday, 11 February 2015

Access Elements of an Array Using Pointer Using C

#include
#include
int main()
{

int i, n;
int *a;

printf("Number of elements to be entered:");
scanf("%d",&n);

a = (int*)calloc(n, sizeof(int));
printf("Enter %d numbers:\n",n);
for( i=0 ; i < n ; i++ )
{
scanf("%d",&a[i]);
}

printf("The numbers entered are: ");
for( i=0 ; i < n ; i++ )
    {
printf("%d ",a[i]);
}
return(0);
}

No comments:

Post a Comment