Description:
- AP :
- In mathematics, an arithmetic progression (AP) or arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant.
- For instance, the sequence 5, 7, 9, 11, 13, 15 … is an arithmetic progression with common difference of 2.
- GP :
- In mathematics, a geometric progression, also known as a geometric sequence, is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio.
- For example, the sequence 2, 6, 18, 54, … is a geometric progression with common ratio 3. Similarly 10, 5, 2.5, 1.25, … is a geometric sequence with common ratio 1/2.
- HP :
- In mathematics, a harmonic progression (or harmonic sequence) is a progression formed by taking the reciprocals of an arithmetic progression.
Pr-requisites:-
- Loops
- Operators
- Data Types
Objective: –
- To understand the concept of
- Continuous looping.
- If-else constructs
- Type Casting
Inputs: –
- Positive integers say ‘A’, ‘R’ and ‘N’, where N > 1
where:
A = First number
R = Common difference(AP & HP), Common ratio(GP)
N = number of terms
Test Case 1:
Enter the First Number ‘A’: 2
Enter the Common Difference / Ratio ‘R’: 3
Enter the number of terms ‘N’: 5
AP = 2, 5, 8, 11, 14
GP = 2, 6, 18, 54, 162
HP = 0.500000, 0.200000, 0.125000, 0.090909, 0.071428
Test Case 2:
Enter the First Number ‘A’: 2
Enter the Common Difference / Ratio ‘R’: 3
Enter the number of terms ‘N’: -5
Invalid input
466