C program to find Sum of numbers in array using pointer | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Saturday, February 29, 2020

C program to find Sum of numbers in array using pointer | My CS Tutorial




C PROGRAM CODE



#include<stdio.h>
main()
{
  int i,n,sum=0,*ptr;
  
  printf("\n ENTER THE RANGE OF ARRAY:\n ");
  scanf("%d",&n);
  
  int var[100-1];
  
  printf("\n 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("\n SUM OF GIVEN NUMBERS = %d\n",sum);
}



OUTPUT:







No comments:

Post a Comment