determine the cumulative sum of n floating point numbers read a new number into the computer during each call to recursive function
Sample input:
n=3
Enter the number:0.8
Enter the number:0.1
Enter the number:0.2
Sample output:
Cumulative sum=1.1
#include<stdio.h>
int n;
float sum(float arr[3]){
float total= 0.0;
int i;
for ( i=0; i<3; i++){
total += arr[i];
}
return total;
}
int main(){
float arr[3];
int i;
for(i = 0; i<3; i++){
printf("Enter element %d\n", (i+1));
scanf("%f", &arr[i]);
}
printf("The total of the numbers is: %f", sum(arr));
}
Comments
Leave a comment