Q:

C program to find sum of following series

0

 C program to find sum of following series:
1+ 1/2 + 1/3 + 1/4 + 1/5 + .. 1/N

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*  
C program to find sum of following series
 1+ 1/2 + 1/3 + 1/4 + 1/5 + .. 1/N
*/

#include<stdio.h>
    
int main()
{
	int i,N;
	float sum;
	
	/*read value of N*/
	printf("Enter the value of N: ");
	scanf("%d",&N);
	
	/*set sum by 0*/
	sum=0.0f;
	
	/*calculate sum of the series*/
	for(i=1;i<=N;i++)
		sum = sum + ((float)1/(float)i);
	
	/*print the sum*/
	
	printf("Sum of the series is: %f\n",sum);
	
	return 0;
}
    Enter the value of N: 10
    Sum of the series is: 5.187378

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now