Print 1 to 100 in C++, without loop and recursion


There are several methods to print numbers without using loops like by using recursive function, goto statement and creating a function outside main() function.

Here is an example to print numbers using goto statement in C++ language,

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
int main() {
   int count=1;
   int x;
   cout << "Enter the max value of x : ";
   cin >> x;
   PRINT:
   cout << " " << count;
   count++;
   if(count<=x)
   goto PRINT;
   return 0;
}

Output

Enter the max value of x : 1

In the above program, we used GOTO statement to print the numbers from 1 to 100 without using loops and recursion.

PRINT:
cout << " " << count;
count++;
if(count<=x)
goto PRINT;

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

613 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements