+92 332 4229 857 99ProjectIdeas@Gmail.com

How to make overlapped series (C++)


Overlapped series
This example shows how to execute two different series in a single for loop at a time. First one satring from 1 which increaments by 1, and the second one also strating from 1 and it increaments by 2.
overlappedSeries() calculates the overlapped series and it takes 1 parameter:
num is the number of times the for loop will execute.

Code

#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "iomanip"
using namespace std;

void overlappedSeries(int num)
{
 for(int i =1,j=1;i<=num;i=i+1,j=j+2)
 {
  cout<<i<<" "<<j<<" ";
 }
 cout<<endl;
}

int main()
{
       overlappedSeries(5);cout<<endl;
       overlappedSeries(6);cout<<endl;
       overlappedSeries(7);cout<<endl;
       overlappedSeries(8);cout<<endl;
       overlappedSeries(9);cout<<endl;

       _getche();
       return 0;
}

Output
1 1 2 3 3 5 4 7 5 9
1 1 2 3 3 5 4 7 5 9 6 11
1 1 2 3 3 5 4 7 5 9 6 11 7 13
1 1 2 3 3 5 4 7 5 9 6 11 7 13 8 15
1 1 2 3 3 5 4 7 5 9 6 11 7 13 8 15 9 17

0 comments: