C PROGRAMMING

write a c program to calculate sum of array elements using pointers

#include<stdio.h>
#include<conio.h>


main()
{
int numArray[10];
int i,n, sum = 0;
int *ptr;
printf("nEnter the size of array : n");
scanf("%d",&n);
for (i = 0; i < n; i++)
{
printf("nEnter %d element of array : ",i+1);
scanf("%d", &numArray[i]);
}
ptr = numArray; /* a=&a[0] */

for (i = 0; i < n; i++) {
sum = sum + *ptr;
ptr++;
}
printf("nThe sum of array elements : %d", sum);

getch();
}

Related Articles

Leave a Reply

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

Back to top button