In this blog, we are going to code
different series that usually asked. Many of us get confused between loops and
conditions. And it is also one of the most asked interview questions.
In the table given below, we have
listed out various number series program.
Let’s find out a simple and easy way
to code these pattern.
S.no.
|
Number Series
|
1.
|
1 + 2 + 3 + 4 + 5 + ... + n
Output
Value of n: 5
Sum: 15
Click to view source
code
|
2.
|
(1*1) + (2*2) + (3*3) + (4*4) + (5*5) + ... + (n*n)
Output
Value of n: 5
Sum: 55
Click to view source
code
|
3.
|
(1) + (1+2) + (1+2+3) + (1+2+3+4) +
... + (1+2+3+4+...+n)
Output
Value of n: 5
Sum:35
Click to view source
code
|
4.
|
0, 1, 1, 2, 3, 5, 8, 13, 21,......
Enter value of n: 6
Fibonacci series:
0 1 1 2 3 5
Click to view source
code
|
For any
query, comment us below.
Previous – Pattern printing program
Keep learning and sharing...
No comments:
Post a Comment