write a c++ function void sum(double& sym,int n) which calculates the sum 1/1+1/2+1/3+...1/n where n is positiv integer.function returns the sum via refrnc parameter..
# include<iostream>
# include<conio.h>
using namespace std;
void sum(double& sum,int n){
float add=0;
cout<<"please enter the value of n"<<endl;
cin>>n;
for (int i=1;i<=n; i++){
add +=1.0/i;
#include<iostream>
usingnamespace std;
void sum(double& sum,int n){ //sum is a reference, so any change of sum will
//be reflected in the variable passed by the calling function.
//
//n is passed to the function from the caller,
// so there is no need to have the user enter it here.
for (int i=1;i<=n; i++){
sum +=1.0/i;
}
}
int main(){
double k=0;
int j=10;
sum(k,j); //k and j are used by sum
cout<<"sum is "<< k<< endl;
}