Series Printing coding 1
CODE NO:- 05
Q)Write a program to display the series 0,0,2,1,4,2,6,3,8,4,…………
#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 i,n,a=0,b=0;
cout<<"\n enter the val of n upto which you to print the series:";
cin>>n;
for(i=0;i<n;i++)
{
if(i%2==0)
{
cout<<a<<" ";
a+=2;
}
else
{
cout<< b<<" ";
b++;
}
}
return 0;
}
We got this output by using DEV C++ (IDE)
Link: For other series printing problems
Q)Write a program to display the series 0,0,2,1,4,2,6,3,8,4,…………
#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 i,n,a=0,b=0;
cout<<"\n enter the val of n upto which you to print the series:";
cin>>n;
for(i=0;i<n;i++)
{
if(i%2==0)
{
cout<<a<<" ";
a+=2;
}
else
{
cout<< b<<" ";
b++;
}
}
return 0;
}
We got this output by using DEV C++ (IDE)
Link: For other series printing problems
Well Explained! :)
ReplyDeleteNice
ReplyDeleteCan u make a post on Bubble sorting??
yes, I will but later
DeleteOhk👍👍😊😊
Delete