Tuesday, November 14, 2017

C++ Code Review: prints 1 to n Without Using Loops, Recursion or Goto Statement

Description: This program prints 1 to n Without Using Loops, Recursion or Goto Statement

Code:

//Compiling Tool: Code::Block IDE with MinGW

//Program prints 1 to n Without Using Loops, Recursion or Goto Statement

 

#include<iostream>

#include<conio.h> //for getch()

 

using namespace std;

 

class Num

{

    public:

    static int i;

    Num()

    {

        cout<<i++<<" ";

    }

};

int Num::i=1;

 

int main()

{

    int n;

    cout<<"Enter value on n:";

    cin>>n;

    Num obj[n];

    return 0;

}     

 

Output:

 clip_image002

f you want to write or construct or program C++ mini-project and do not know how or from where to start buy this simple e-book: Code Review of 26 C++ mini-projects. For book sample click this link.

Add your comments in below available comment box.

Note: Click these label/tags to view all related posts. Tags: C++Code

 

…till next post, bye-bye & take care.

No comments:

Post a Comment