VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-print-upto-100-without-using-loops/

⇱ Print 1 to 100 without loop using Goto and Recursive-main - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Print 1 to 100 without loop using Goto and Recursive-main

Last Updated : 6 Apr, 2023

Our task is to print all numbers from 1 to 100 without using a loop. There are many ways to print numbers from 1 to 100 without using a loop. Two of them are the goto statement and the recursive main.

Follow the steps mentioned below to implement the goto statement:

  • declare variable i of value 0
  • declare the jump statement named begin, which increases the value of i by 1 and prints it.
  • write an if statement with condition i < 100, inside which call the jump statement begin

Below is the implementation of the above approach:


Output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

Time complexity: O(1)
Auxiliary Space: O(1)

Follow the steps mentioned below to implement the recursive main:

  • declare variable i of value 1.
  • keep calling the main function till i < 100.

Below is the implementation of the above approach:


Output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

Time complexity: O(1)
Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: