Contact Learn C
Copy Program Share Program

Program 195:To print Sum of numbers in array usng Pointers

Program 195:
 
#include<stdio.h>
main()
{
  int i,n,sum=0,*ptr;
  printf("Enter number \n");
  scanf("%d",&n);
  int var[n-1];
  printf("Enter values in array\n");
  for(i=0;i<n;i++)
  {
   scanf("%d",&var[i]);
  }
  ptr=&var[0];//you can also use ptr=var;
  for(i=0;i<n;i++)
  {
   sum+=*ptr;
   ptr++;
  }
  
  printf("Sum=%d\n",sum);
}

Explanation:

//Coming Soon...

Output:








 

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide