C program to find the sum of all elements of an array using pointers as arguments

by Nideesh C on April 13, 2011 · 0 comments

in C Programming




/* C program to find the sum of all elements of  an array using pointers as arguments */

#include <stdio.h>

void main()
{
static int array[5]={ 200,400,600,800,1000 };
int sum;

int addnum(int *ptr);     /* function prototype */

sum = addnum(array);

printf(“Sum of all array elements = %5d\n”, sum);

}     /* End of main() */

int addnum(int *ptr)
{
int index, total=0;

for(index = 0; index < 5; index++)
{
total += *(ptr+index);
}
return(total);
}
/*———————————–
Output
Sum of all array elements =  3000
————————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to read N integers and store them in an array A, and so find the sum of all these elements using pointer. Output the given array and and the computed sum with suitable heading
  2. C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
  3. C program to read a matrix A (MxN) and to find the following using functions a) Sum of the elements of each row b) Sum of the elements of each column c) Find the sum of all the elements of the matrix Output the computed results with suitable headings
  4. C program to find accept a matrix of order M x N and find the sum of the main diagonal and off diagonal elements
  5. C program to sort given N elements using SELECTION sort method using functions a) To find maximum of elements b) To swap two elements

Leave a Comment

Previous post:

Next post: