GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Generate below sequence of numbers for given N.

Sequence goes like this : 1, 2, 3, 5, 6, 7, 10, 11, 12, 16, 17, 18, 23, …..

asked Nov 6, 2016 by Jeevan K

Good question.

Thanks arjun890626

2 Answers

 
Best answer

Below is the C++ implementation for above sequence:

#include <iostream>

using namespace std;

int main()
{
    int Size,Gap=1,start=1,Count=0;

    cout<<"Enter the limit upto which you want the sequence: ";

    cin>>Size;
    cout<<endl;

    while(start<=Size)
    {
        cout<<start<<" ";
        start++;
        Count++;
        if(Count==3)
        {
            Count=0;
            start+=Gap;
            Gap++;
        }
    }
    return 0;
}

Hope that helped. Thank You for asking such good questions. Up vote it , if you are satisfied.

answered Nov 6, 2016 by Mazhar MIK
selected Nov 7, 2016 by Jeevan K
#include void main() { int l,i=1,n,k; printf("enter ur limit "); scanf(" %d",&l); for(k=0;k<l;k++) { n=i+k; for(i=n;i<=(n+2);i++) printf(" %d",i); } } I hope u can understand this
answered Nov 28, 2016 by Yashu guntur
...