Q:

C Program to Calculate Sum of all Elements of an Array using Pointers as Arguments

0

C Program to Calculate Sum of all Elements of an Array using Pointers as Arguments

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
 
void main()
{
	static int array[5] = { 200, 400, 600, 800, 1000 };
	int sum;
 
  	int addnum(int *ptr);
     	sum = addnum(array);
 
        printf("Sum of all array elements = %5d\n", sum);
 
}
 
int addnum(int *ptr)
{
	int index, total = 0;
	for (index = 0; index < 5; index++) 
        {
		total += *(ptr + index);
	}
	return(total);
 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now