PROGRAM TO ADD ALL THE ELEMENTS OF ARRAY USING POINTERS

/*PROGRAM TO AD ALL THE ELEMENTS OF ARRAY USING POINTERS*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i,sum=0;
int *p;
clrscr();
printf(“Enter the size of array: “);
scanf(“%d”,&n);
printf(“Enter %d elements in the array:\n”,n);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
p=&a[0];
printf(“Entered elements are:\n”);
for(i=0;i<n;i++)
{
printf(“%5d”,*p);
sum=sum+(*p);
p++;
}
printf(“\nSum of elements of array is: %d”,sum);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *