(C++) CPP Programs - 29

Friday, December 14, 2007

29. Write a C program to read N integers and store them in an array A, and so find the sum of all these elements using pointer. Output the given array and the computed sum with suitable heading.

/* Addition using pointers */

#include
#include

void main()
{
int a[45],*p;
int sum=0,i,n;
clrscr();

printf("\nEnter no. of elements\n");
scanf("%d",&n);

printf("Enter the numbers one by one\n");
for(i=0;i < n;i++)
scanf("%d",&a[i]);
p=a;
for(i=0;i < n;i++)
sum+=*p++;

printf("The sum of %d numbers=%d\n\a",n,sum);

getch();
}

0 comments:

Post a Comment

Chitika

About This Blog

Followers

Blog Archive

  © Blogger template The Professional Template II by Ourblogtemplates.com 2009

Back to TOP