Answer to Question #218621 in C for Hemambar

Question #218621

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


1
Expert's answer
2021-07-20T17:05:44-0400
#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));
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS