Monday, July 13, 2015

Pointer and array

#include <stdio.h>
int main()
{
  int i,arr[5],sum=0;

  printf("Enter 5 numbers:");

  for(i=0;i<5;i++)
{
      scanf("%d",(arr+i));
      sum += *(arr+i); 
  }
  printf("Sum=%d",sum);

  return 0;
}


output: 


3 4 5 6 7
Sum=25

No comments:

Post a Comment