You may have made a program to print numbers from 1 to n utilizing
circles, recursion or goto articulation. Be that as it may, have you at any point pondered doing this
without the assistance of circles, recursion or goto? It very well may be managed without utilizing such
things as clarified in beneath program:
#include<iostream>
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;
}
In this program, we are utilizing the concept of static information
part and cluster of articles. Class Num
contains a static variable I whose worth
will stay till the program ends. We are making a variety of articles
about class Num. In this program we are
making n objects, estimation of n relies upon the input we give. The default
constructor is required for all items individually. In the constructor, the worth
of I is printed and is augmented
by one in each call. Along these lines numbers from 1 to n are printed.
Output
If you have any questions or any recommendation with respect to above
the program then you can ask it by remarking underneath.