write a program in c ++to find the sum of following series S=1+1/2+1/3+1/4+........upto nth term
Answers
Answered by
1
Heya
float sum(int n){
float i, sum = 0 ;
for (i = 1; i <= n; i++)
sum = sum + 1/i;
return sum ;
}
int main()
{
printf("Enter the value of n \n");
scanf("%d", &n);
printf("Sum is %f \n", sum(n)) ;
return 0;
}
Hope this helps ^^"
float sum(int n){
float i, sum = 0 ;
for (i = 1; i <= n; i++)
sum = sum + 1/i;
return sum ;
}
int main()
{
printf("Enter the value of n \n");
scanf("%d", &n);
printf("Sum is %f \n", sum(n)) ;
return 0;
}
Hope this helps ^^"
Similar questions