
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Sum of the series 0.7, 0.77, 0.777 … upto n terms in C++
In this problem, we are given n terms of a number. The series is 0.7, 0.77, 0.777…. Our task is to create a program to find the sim of the series 0.7, 0.77, 0.777 … upto n terms.
Let’s take an example to understand the problem,
Input 4
Output
Explanation −0.7 + 0.77 + 0.777 + 0.7777 = 3.0247
To solve this problem, we will derive the formula for sum of series. Let’s find the general formula for it,
sum = 0.7 + 0.77 + 0.777 + ... upto n terms sum = 7 (0.1 + 0.11 + 0.111 + … upto n terms) sum = 7 (9/9)(0.1 + 0.11 + 0.111 + … upto n terms) sum = 7/9(0.9 + 0.99 + 0.999 + … upto n terms) sum = 7/9 ( (1 - 0.1) + (1 - 0.01) + (1 - 0.001) + … upto n terms ) sum = 7/9 ( (1+ 1 + 1 + … + upto n) - (0.1 + 0.01 + 0.001 + … upto n terms) ) sum = 7/9 ( (n) - (1/10 + 1/100 + 1/1000 + … upto n terms) ) sum = 7/9 ( n - 0.1 * ((1 - (0.1)n)/ (1 - 0.1)) ) sum = 7/9 ( n - 0.1 * ((1 - (0.1)n)/ (0.9)) ) sum = 7/9 ( n - ((1 - (1/10n) )/9) ) sum = 7/81 ( 9n - (1 - (1/10n) ) ) sum = 7/81 (9n - 1 + 10-n)
This formula given the general formula for the sum of series upto n terms.
Example
Program to illustrate the working of our solution,
#include <iostream> #include <math.h> using namespace std; float calcSeriesSum(int n) { return ( (.08641) * (9*n - 1) + pow(10, (-1) * n) ); } int main() { int n = 5; cout<<"The sum of series 0.7, 0.77, 0.777, ... upto n terms is "<<calcSeriesSum(n); return 0; }
Output
The sum of series 0.7, 0.77, 0.777, ... upto n terms is 3.80205
- Related Articles
- Find sum of the series ?3 + ?12 +.... upto N terms in C++
- Find sum of the series 1+22+333+4444+... upto n terms in C++
- C++ Program to find the sum of the series 23+ 45+ 75+….. upto N terms
- Find Sum of Series 1^2 - 2^2 + 3^2 - 4^2 ... upto n terms in C++
- Sum of series 2/3 – 4/5 + 6/7 – 8/9 + …… upto n terms
- Sum of the series 1 / 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + … + upto n terms in C++
- Sum of the first N terms of the series 2,10, 30, 68,…. in C programming
- Sum of the first N terms of the series 5,12, 23, 38…. in C Programming
- C Programming for sum of the series 0.6, 0.06, 0.006, 0.0006, …to n terms
- Sum of the first N terms of the series 2, 6, 12, 20, 30…. in c programming
- Find the sum:\( 4-\frac{1}{n}+4-\frac{2}{n}+4-\frac{3}{n}+\ldots \) upto \( n \) terms
- Sum of the series 1.2.3 + 2.3.+ … + n(n+1)(n+2) in C
- Find fibonacci series upto n using lambda in Python
- C++ program to get the Sum of series: 1 – x^2/2! + x^4/4! -…. upto nth term
- Sum of the series 1^1 + 2^2 + 3^3 + ... + n^n using recursion in C++

Advertisements