The document discusses generating arithmetic, geometric, and harmonic progression series. It explains that arithmetic series have a constant difference between terms, geometric series have a constant ratio, and harmonic series have reciprocals that form an arithmetic progression. Examples are provided of inputting initial values and generating the corresponding series output for each progression type. Pre-requisites of loops, operators, and data types are also listed.
6. Assignment 5
WAP to generate AP, GP, HP series.
Input: Read integer ‘A’, ‘R’ and ‘N’.
7. Assignment 5
WAP to generate AP, GP, HP series.
Input: Read integer ‘A’, ‘R’ and ‘N’.
where:
A = First number
R = Common difference(AP & HP), Common ratio(GP)
N = number of terms
8. Assignment 5
WAP to generate AP, GP, HP series.
Input: Read integer ‘A’, ‘R’ and ‘N’.
where:
A = First number
R = Common difference(AP & HP), Common ratio(GP)
N = number of terms
Output:
9. Assignment 5
WAP to generate AP, GP, HP series.
Input: Read integer ‘A’, ‘R’ and ‘N’.
where:
A = First number
R = Common difference(AP & HP), Common ratio(GP)
N = number of terms
Output: Print AP , GP and HP series.
14. Assignment 5
How to generate AP series?
First term ‘A’ = 3, Common difference ‘R’ = 3 and ‘N’ = 3
15. Assignment 5
How to generate AP series?
First term ‘A’ = 3, Common difference ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
16. Assignment 5
How to generate AP series?
First term ‘A’ = 3, Common difference ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
Sum of previous term and common difference(R) -> next term
17. Assignment 5
How to generate AP series?
First term ‘A’ = 3, Common difference ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
Sum of previous term and common difference(R) -> next term
The series : 3, ?
18. Assignment 5
How to generate AP series?
First term ‘A’ = 3, Common difference ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
Sum of previous term and common difference(R) -> next term
The series : 3, ?
What is the next term?
3 ?
19. Assignment 5
How to generate AP series?
First term ‘A’ = 3, Common difference ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
Sum of previous term and common difference(R) -> next term
The series : 3, ?
What is the next term?
3 6
3 + 3 = 6
20. Assignment 5
How to generate AP series?
First term ‘A’ = 3, Common difference ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
Sum of previous term and common difference(R) -> next term
The series : 3, 6, ?
What is the next term?
3 9
6
6 + 3 = 9
21. Assignment 5
How to generate AP series?
First term ‘A’ = 3, Common difference ‘R’ = 3 and ‘N’ = 3
The series : 3, 6, 9
26. Assignment 5
How to generate GP series?
First term ‘A’ = 3, Common ratio ‘R’ = 3 and ‘N’ = 3
27. Assignment 5
How to generate GP series?
First term ‘A’ = 3, Common ratio ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
28. Assignment 5
How to generate GP series?
First term ‘A’ = 3, Common ratio ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
Product of previous term and common ratio (R) -> next term
29. Assignment 5
How to generate GP series?
First term ‘A’ = 3, Common ratio ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
Product of previous term and common ratio (R) -> next term
The series : 3, ?
30. Assignment 5
How to generate GP series?
First term ‘A’ = 3, Common ratio ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
Product of previous term and common ratio (R) -> next term
The series : 3, ?
What is the next term?
?
3
31. Assignment 5
How to generate GP series?
First term ‘A’ = 3, Common ratio ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
Product of previous term and common ratio (R) -> next term
The series : 3, ?
What is the next term?
3 * 3 = 9
9
3
32. Assignment 5
How to generate GP series?
First term ‘A’ = 3, Common ratio ‘R’ = 3 and ‘N’ = 3
How to find the next term ?
Product of previous term and common ratio (R) -> next term
The series : 3, 9, ?
What is the next term?
9 * 3 = 27
27
9
3
33. Assignment 5
How to generate GP series?
First term ‘A’ = 3, Common ratio ‘R’ = 3 and ‘N’ = 3
The series : 3, 9, 27
38. Assignment 5
How to generate HP series?
First term is –> 1/A (A = 3) and the AP series : 3, 6, 9
39. Assignment 5
How to generate HP series?
First term is –> 1/A (A = 3) and the AP series : 3, 6, 9
How to find the next term ?
40. Assignment 5
How to generate HP series?
First term is –> 1/A (A = 3) and the AP series : 3, 6, 9
How to find the next term ?
Reciprocal of next term in AP series-> next term
41. Assignment 5
How to generate HP series?
First term is –> 1/A (A = 3) and the AP series : 3, 6, 9
How to find the next term ?
Reciprocal of next term in AP series-> next term
The series : 1/3, ?
42. Assignment 5
How to generate HP series?
First term is –> 1/A (A = 3) and the AP series : 3, 6, 9
How to find the next term ?
Reciprocal of next term in AP series-> next term
The series : 1/3, ?
In float : 0.333333, ?
43. Assignment 5
How to generate HP series?
First term is –> 1/A (A = 3) and the AP series : 3, 6, 9
How to find the next term ?
Reciprocal of next term in AP series-> next term
The series : 1/3, ?
In float : 0.333333, ?
What is the next term?
1/3 ?
44. Assignment 5
How to generate HP series?
First term is –> 1/A (A = 3) and the AP series : 3, 6, 9
How to find the next term ?
Reciprocal of next term in AP series-> next term
The series : 1/3, 1/6, ?
In float : 0.333333, 0.166667, ?
What is the next term?
1/3 1/6
1 / (3+3) = 1/6
45. Assignment 5
How to generate HP series?
First term is –> 1/A (A = 3) and the AP series : 3, 6, 9
How to find the next term ?
Reciprocal of next term in AP series-> next term
The series : 1/3, 1/6, ?
In float : 0.333333, 0.166667, 0.111111
What is the next term?
1/3 1/6
1 / (3+3) = 1/9
1/9
47. Assignment 5
For example:- A = 3, R = 3 , N = 3
The HP series is :- 1/3, 1/6, 1/9
Print series in float:-
48. Assignment 5
For example:- A = 3, R = 3 , N = 3
The HP series is :- 1/3, 1/6, 1/9
Print the series in float values
Print series in float:-
49. Assignment 5
For example:- A = 3, R = 3 , N = 3
The HP series is :- 1/3, 1/6, 1/9
Print the series in float values
In float : 0.333333, 0.166667, 0.111111
Print series in float:-
51. Assignment 5
int num1 = 3 , num2 = 2;
float res = num1 / num2;
Can you guess the output ?
52. Assignment 5
int num1 = 3 , num2 = 2;
float res = num1 / num2;
It will print 1.000000
Can you guess the output ?
53. Assignment 5
int num1 = 3 , num2 = 2;
float res = num1 / num2;
It will print 1.000000
int num1 = 3 , num2 = 2;
float res = (float) num1 / num2;
Can you guess the output ?
54. Assignment 5
int num1 = 3 , num2 = 2;
float res = num1 / num2;
It will print 1.000000
int num1 = 3 , num2 = 2;
float res = (float) num1 / num2;
It will print 1.500000
Can you guess the output ?
3 / 2 1.000000
=
int float
int
3.000000 / 2 1.500000
=
float float
int
55. Assignment 5
int num1 = 3 , num2 = 2;
float res = num1 / num2;
It will print 1.000000
int num1 = 3 , num2 = 2;
float res = (float) num1 / num2;
It will print 1.500000
Can you guess the output ?
Doing int / int and storing in float.
So, decimal part(.5 of 1.5) will be
truncated and only 1.000000 will
be stored in float.
Doing float / int and storing in
float.
So, decimal part(.5 of 1.5) will not
be truncated and 1.500000 will be
stored in float. This is typecasting