Tuesday, 28 January 2014

c program to print n numbers without using loop

c 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. You can see another program to print prime number using recursion for refreshing recursion concept. Lets See the program to make clear view that how recursion works.

c program to print n numbers without using loop:

#include <stdio.h>
#include <conio.h>

void print(int p)
{
     if(p>0)
     {
          print(p-1);                    // recursive call;
          printf("\n\n %d \t", p);
     }
     return;
}

int main()
{
     int n;
     printf("enter the number\n\n");
     scanf("%d",&n);                  // number to which you wnat to print
     print(n);
     getch();
     return 0;
}

Output of c program to print n numbers without using loop:

C program to print n numbers without loop

No comments:

Post a Comment