The points we covered in this article are mention below
- Question
- question analysis
- solution
- explanation
- exception
0 , 0 , 2 , 1 , 4 , 2 , 6 , 3 , 8 , 4 , 10 , 5 , 12 , 6 , 14 , 7 , 16 , 8
Question analysis
This series is a mixture of 2 series - all the odd term in series form
a geometric series and all the even terms form yet another geometric series.
wap to print the series
In the odd places this series is produces a geometric series and in the even places of series produces a geometric series.
solution
#include<iostream>
using namespace std;
int main()
{
int n,a=0,b=0,i;
cout<<"Enter the number :"<<endl;
cin>>n;
for(i=1;i<=n;i++) //for odd positions
{
if(i%2!=0)
{
if(i>1)
a=a+2;
cout<<a<<" ";
}
else //for even position
{
b=a/2;
cout<<b<<" ";
}
}
return 0;
Output
Explanation
- first we required the header file then start of the main function.
- Then we declare 4 variables , first the 'n' variable is for asking the user to enter then number to display the series till the number user enter. then we take 'a' variable for printing the even positions and take variable 'b' for printing the odd positions.
- Then we run a for loop till the user entered number and use the if condition for checking that (if user 11 then its start checking from 1 if condition check that 1%2 !=0 then its satisfy the condition and its come inside the if condition and check again if(i>1) which is not true so then it come to else part and check b=a/2 where 0=0/2=0 so it is print in first place 0 ;
- then the next number is 2 and it check the condition if(i%2!=0) this condition is become false because of not equal operator in this case so its come to the else part now and b=a/2 where 0=0/2=0 print on the screen 0.
- Then further conditions are satisfy similarly try yourself .
- If still any doubt watch out the given video with fully explanation.
Exceptional case
if it question ask you to print a specific position in the series.
Coding
#include<iostream>
using namespace std;
int main()
{
int n,a=0,b=0,i;
cout<<"Enter the number :"<<endl;
cin>>n;
for(i=1;i<=n;i++) //for odd positions
{
if(i%2!=0)
{
if(i>1)
a=a+2;
}
else //for even position
{
b=a/2;
}
}
if(n%2!=0) //for even positions
{
printf("\n %d term of series is %d\t",n,a);
}
else //for odd positions
{
printf("\n%d term of series is %d\t",n,b);
}
return 0;
}
Output
More problem on TCS paper
1 , 1 , 2 , 3 , 4 , 9 , 8 , 27 , 16 , 81 , 32 , 243 , 64 , 729 , 128 , 2187
Also check Out
Also check Out Projects for Resume
Problems On C++
Q-2) Vectors In c++
Feedback
- That is for TCS NQT Number series problem hope you enjoy the article and understand this explanation clearly ,
- if still have you any doubts please comment below and if any suggestion for us give us through the comment and please share the article with your friends if you like this.
Post a Comment
Post a Comment
Please do not spam in comment