English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
There are several ways to print numbers without using loops, such as using recursive functions, goto statements, and creatingmain()
function.
This is a function using C ++This is an example of using the goto statement to print numbers in the language,
#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 Result
Enter the max value of x : 1
In the above program, we used the GOTO statement to print from1To10The number 0 without using loops and recursion.
PRINT: cout << " " << count; count++; if(count<=x) goto PRINT;