- #1

- 38

- 2

- Homework Statement:
- Calculate the sum of the square root

- Relevant Equations:
- -

C:

```
#include<stdio.h>
#include<math.h>
double foo(int n){
if(n==1){
return(1);
}
if(n!=0){
return( sqrt((n)+foo(n-1) ) );
}
}
int main(){
int num;
printf("Enter the number: ");
scanf("%d",&num);
foo(num);
printf(" %lf ",foo(num));
return(0);
}
```

I want to calculate the sum of the square root. For example if the input is 5, I want to calculate sqrt(5)+sqrt(4)+sqrt(3)+sqrt(2)+sqrt(1) recursively. But it does not work. If the input is 5, output -> 2.735877.