Friday, 25 August 2017

Print numbers from 1 to n without the help of loops.

Input: 
The first line of the input contains T denoting the
number of testcases. First line of test case containnumber n.

Output: 
Numbers from 1 to n will be printed.

Constraints:
1 <=T<= 100
1 <=N<= 990

Example:
Input:1
10
Output:1 2 3 4 5 6 7 8 9 10
#include <stdio.h>
void print(int p)
{
     if(p>0)
     {
          print(p-1);                   
          printf("%d ", p);
     }
     return;
}
int main()
{
     int t,n;
     scanf("%d",&t);
     while(t--)
     {
     scanf("%d",&n);                 
     print(n);
     printf("\n");
     }
     return 0;
}

No comments:

Post a Comment