- 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

# C++ Ratio of Mth and Nth Terms of an A. P. with Given Ratio of Sums

Discuss a problem where we are given a ratio of sums of m and n terms of A.P. We need to find the ratio of mth and nth terms.

Input: m = 8, n = 4 Output: 2.142 Input: m = 3, n = 2 Output: 1.666 Input: m = 7, n = 3 Output: 2.6

## Approach to Find the Solution

To find the ratio of m^{th} and n^{th} terms using code, we need to simplify the formula. Let S_{m} be the sum of first m terms and S_{n} be the sum of the first n terms of the A.P.

a - first term,

d - common difference,

Given, **S _{m} / S_{n} = m^{2} / n^{2}**

Formula for S, S_{m} = (m/2)[ 2*a + (m-1)*d ]

m^{2} / n^{2} = (m/2)[ 2*a + (m-1)*d ] / (n/2)[ 2*a + (n-1)*d ]

m / n = [ 2*a +(m-1) *d ] / [ 2*a +(m-1) *d ]

Using cross multiplication,

n[ 2*a + (m−1)*d ] = m[ 2*a + (n−1)*d ]

2an + mnd - nd = 2am + mnd - md

2an - 2am = nd - md

(n - m)2a = (n-m)d

**d = 2a**

The formula of m^{th} term is,

T_{m} = a + (m-1)d

Ratio of m^{th} and n^{th} term is,

T_{m} / T_{n} = a + (m-1)d / a + (n-1)d

Replacing d with 2a,

Tm / Tn = a + (m-1)*2a / a + (n-1)*2a

Tm / Tn = a( 1 + 2m − 2 ) / a( 1 + 2n − 2 )

**Tm / Tn = 2m - 1 / 2n - 1**

So now we have a simple formula to find the ratio of m^{th} and n^{th} terms. Let’s see C++ code for this.

## Example

**C++ Code for the Above Approach**

#include <bits/stdc++.h> using namespace std; int main(){ float m = 8, n = 4; // calculating ratio by applying formula. float result = (2 * m - 1) / (2 * n - 1); cout << "The Ratio of mth and nth term is: " << result; return 0; }

## Output

The ratio of mth and nth term is: 2.14286

## Conclusion

In this tutorial, we discussed a problem to find the ratio of mth and nth term with a given ratio of sums which we solved by simplifying the formula of the sum of m terms and formula of mth term. We also discussed the C++ program for this problem which we can do with programming languages like C, Java, Python, etc. We hope you find this tutorial helpful.

- Related Articles
- Find Pth term of a GP if Mth and Nth terms are given in C++
- What are the pitfalls of the Price Earnings Ratio (P/E Ratio)?
- If the ratio of the sum of first n terms of two A.P’s is $( 7n\ +1)$: $( 4n\ +\ 27)$, find the ratio of their $m^{th}$ terms.
- Transformation Ratio and Turn Ratio of Single-Phase Transformer
- Find the sum of $n$ terms of an A.P. whose nth terms is given by $a_n = 5 – 6n$.
- If the ratio of the sum of the first n terms of two APs is $(7n + 1)$: $(4n + 27)$, then find the ratio of their 9$^{th}$ terms.
- How to maintain the aspect ratio of an element with CSS?
- The radii of two cylinders are in the ratio $2 : 3$ and their heights are in the ratio $5:3$. Calculate the ratio of their volumes and the ratio of their curved surfaces.
- The ratio of radii of two cylinders is 1:2 and the heights are in the ratio 2:3. The ratio of their volumes is_____.
- The ratio of volumes of two cones is $4 : 5$ and the ratio of the radii of their bases is $2:3$. Find the ratio of their vertical heights.
- The sum of first seven terms of an A.P. is 182. If its 4th and the 17th terms are in the ratio 1 : 5, find the A.P.
- Explain ratio and proportion with example.
- The nth term of an A.P. is given by $(-4n + 15)$. Find the sum of first 20 terms of this A.P.
- Difference Between Acid Test Ratio and Current Ratio
- Find the sum of the first 25 terms of an A.P. whose nth term is given by $a_n = 2 – 3n$.