Saturday, 25 February 2017

How will you print numbers from 1 to 100 without using loop?

How will you print numbers from 1 to 100 without using loop?

We can use recursion for this purpose.
/* Prints numbers from 1 to n */
void printNos(unsigned int n)
{
  if(n > 0)
  {
    printNos(n-1);
    printf("%d ",  n);
  }
}

No comments:

Post a Comment