Write A C Program (WAP) to Calculate the Sum Of Elements Using Pointers

Leave a Comment
/* The following program will first ask the user, number of elements. And then user enters the specified number of elements. Then the program will use the concept of pointers to find the sum all the elements in the list */

#include<stdio.h>
#include<conio.h>
 void main()
 {
 int a[10],sum=0;
 int *j;
 int i,n;
 printf("Enter how many elements u want to add:");
 scanf("%d",&n);
 printf("Enter the elements:");
 for(i=0;i<n;i++)
 {
 scanf("%d",&a[i]);
 }
  j=&a[0];
 for(i=0;i<n;i++)
     {


       sum=sum+*j;
       j++;
     }
 printf("sum=%d",sum);
 getche();
}



Output
Write A C Program (WAP) to Calculate the Sum Of Elements Using Pointers
Write A C Program (WAP) to Calculate the Sum Of Elements Using Pointers

0 comments: