Series code 2
CODE NO:- 06
Q)Find the no. for a user given position for this series 0,0,2,1,4,2,6,3,8,4,…
For example: (1) At position 4 you should get no. :1
(2)At position 9 you should get no. :8
#LOGIC
According to the given series, we can conclude that :
1) At even indexes, we are having a series which starts from 0 and gets incremented by (+2) .
2)At odd indexes, we are having a series which starts from 0 and gets incremented by (+1) .
NOTE: Here we are considering 0 as starting index.
Q)Find the no. for a user given position for this series 0,0,2,1,4,2,6,3,8,4,…
For example: (1) At position 4 you should get no. :1
(2)At position 9 you should get no. :8
#LOGIC
According to the given series, we can conclude that :
1) At even indexes, we are having a series which starts from 0 and gets incremented by (+2) .
2)At odd indexes, we are having a series which starts from 0 and gets incremented by (+1) .
NOTE: Here we are considering 0 as starting index.
![]() |
#Program (In C++):
#include<iostream>
using namespace std;
int main()
{
int n,t;
cout<<"\n enter the position :";
cin>>n;
if(n%2==0)
{
n=n/2;
t=(n-1);
cout<<"The no. at given position is:"<<t;
}
else
{
n=n/2+1;
t=(n-1)*2;
cout<<"The no. at given position is:"<<t;
}
return 0;
}
We got this output by using DEV C++ (IDE)
output: 1
output:2
Link: For other series printing problems
😊👍👍 nice
ReplyDelete