Home » C programs » Sum of series C programs

C program to calculate the sum of series 1 +1/x^1 + 1/x^2 + 1/x^3 ... + 1/x^n terms

Here, we are going to implement a c program that will find the sum of series 1 +1/x^1 + 1/x^2 + 1/x^3 ... + 1/x^n terms.
Submitted by IncludeHelp, on March 04, 2018

Program to calculate sum of series 1 +1/x^1 + 1/x^2 + 1/x^3 ... + 1/x^n terms in C



#include <stdio.h>
#include <math.h>

int main()
{
	int x,n,i;
	float sum=0;
	
	printf("Enter total number of terms: ");
	scanf("%d",&n);
	
	printf("Enter the value of x: ");
	scanf("%d",&x);	
	
	for(i=1; i<=n; i++){
		sum += 1+(1/pow(x,i));
	}
	
	printf("Sum of the series: %f\n",sum);
	return 0;
}

Output

Enter total number of terms: 5
Enter the value of x: 2 
Sum of the series: 5.968750

Solution

Series is:
1+1/x^1 + 1/x^2+ 1/x^3 ... + 1/x^n

Here,
    x=2
    n=5

1+1/2^1 + 1+1/2^2 + 1+1/2^3 + 1+1/2^4 + 1+1/2^5
1+1/2 + 1+1/4 + + 1+1/8 + 1+1/16 + 1+1/32
1+0.5 + 1+0.25 + 1+0.125 + 1+0.0625 + 1+0.03125
= 5.968750

Read more...






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.