Answers for "Sum of Array Elements using Pointers"

C
0

Sum of Array Elements using Pointers

#include <stdio.h>

int main()
{
   int n,i;
   printf("How many elements do you want in you array:\n");
   scanf("%d",&n);
   int ara[n];
   for(i=0;i<n;i++){
       scanf("%d",&ara[i]);
   }
   printf("\n");
   printf("The created array is:\n");
   
   for(i=0;i<n;i++){
       printf("%d ",ara[i]);
   }
   printf("\n\n");
   //
   int *ptr,sum=0;
   for(ptr=&ara[0];ptr<=&ara[n];ptr++){
       sum+=*ptr;
   }
   
   printf("Sum is %d\n",sum);
   

    return 0;
}
Posted by: Guest on August-24-2021

Code answers related to "Sum of Array Elements using Pointers"

Code answers related to "C"

Browse Popular Code Answers by Language