60.5k views
0 votes
How would you print from 1 to 1000

User Jordani
by
6.4k points

1 Answer

1 vote

Answer:

There are two ways to print 1 to 1000

  1. Using Loops.
  2. Using Recursion.

Step-by-step explanation:

Using loops

for(int i=1;i<=1000;i++)

{

cout<<i<<" ";

}

Using recursion

Remember you can implement recursion using a function only.

void print(int n)

{

if(n==0)

return;

print(n-1);

cout<<n<<" "';

}

you should pass 1000 as an argument to the function print.

User Andray
by
6.7k points