View All C Programs

 Previews Example  View All C Programs Next Example 

Program to print n numbers without using loop in C

This program to print n numbers without using loop. This c program will print the n numbers without using any loop. Here we uses the concept of recursion.
#include <stdio.h>
#include <conio.h>
  void print(int p)
{
     if(p>0)
     {
          print(p-1);           // recursive call;
          printf("%d \n", p);
     }
     return;
}

int main()
{
     int n;
     printf("Enter the number : ");
     scanf("%d",&n);              // number to which you wnat to print
     print(n);
     getch();
     return 0;
}
Result
Enter the number : 5
1
2
3
4
5