Table of Contents
C Program to find Sum of Array Elements Using Function
Here in this tutorial we have explained and implemented a c program to find the sum of array elements using function by passing array as function parameter.
C Program to find Sum of Array Elements Using Function is given below
#include <stdio.h>
float calculateSum(float num[]);
int main( )
{
float result, num[] = {23.4, 55, 22.6, 3, 40.5, 18};
// num is and array and passed to function calculateSum()
result = calculateSum(num);
printf(“Result = %.2f”, result);
return 0;
}
float calculateSum(float num[])
{
float sum= 0.0;
for (int i = 0; i < 6; ++i)
{
sum += num[i];
}
return sum;
}
Output