- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
#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;
Advertisements