- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find sum of the series ?3 + ?12 +.... upto N terms in C++
In this problem, we are given an integer value N. Our task is to find Sum of Series ?3 + ?12 + ... upto n terms.
The series is $\sqrt3 + \sqrt12 + \sqrt27 + \sqrt48 + ...$
I.e. It is a series of square roots.
Let's take an example to understand the problem,
Input : N = 3 Output : 10.3922
Explanation −
$\sqrt3 + \sqrt12 + \sqrt27 = 1.7320 + 3.4641 + 5.1961 = 10.3922$
Solution Approach
A simple approach to solve the problem is finding the general term of the series and then finding the sum till n terms. And calculating the sum using formula will reduce the time to O(1).
The series is,
$\sqrt3 + \sqrt12 + \sqrt27 + \sqrt48 + ...$
Here, we have $\sqrt3$ common in all terms. On taking it as common we have,
$\Rightarrow\:\sqrt{3}(\sqrt{1}\:+\:\sqrt{4}\: +\: \sqrt{9} \:+\: \sqrt{16}\:+\:\dotsm)$
$\Rightarrow\:\sqrt{3}(1\:+\:2\:+\:3\:+\:4+\:\dotsm)$
So, the general term is,
$\mathrm{T_n\:=\:n*\sqrt{3}}$
Using this we can find the sum till n terms of the series,
$\mathrm{Sum}\:=\:\sum{n}^*\sqrt{3}$
$\mathrm{Sum}\:=\:\sqrt{3}^*\sum{n}$
$\mathrm{Sum}\:=\:(\sqrt{3})^*(n^*(n+1))/2-n$
Example
Program to illustrate the working of our solution
#include<iostream> #include<math.h> using namespace std; float calcSumNTerms(float n) { return ((sqrt(3)) * ((n*(n+1))/2)); } int main() { float n = 25; cout<<"The sum of series upto n terms is "<<calcSumNTerms(n); return 0; }
Output
The sum of series upto n terms is 562.917
- Related Articles
- Find sum of the series 1+22+333+4444+... upto n terms in C++
- Sum of the series 0.7, 0.77, 0.777 … upto n terms in C++
- Find Sum of Series 1^2 - 2^2 + 3^2 - 4^2 ... upto n terms in C++
- C++ Program to find the sum of the series 23+ 45+ 75+….. upto N terms
- 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++
- Find the sum:( 4-frac{1}{n}+4-frac{2}{n}+4-frac{3}{n}+ldots ) upto ( n ) terms
- Sum of the first N terms of the series 2, 6, 12, 20, 30…. in c programming
- Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + .. + n in C++
- Find fibonacci series upto n using lambda in Python
- 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++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- C++ program to find the sum of the series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n
- Sum of the series 1^1 + 2^2 + 3^3 + ... + n^n using recursion in C++
