C PROGRAM TO PRINT NUMBERS 1 TO N WITHOUT USING LOOPS

#include<stdio.h>
void print_numbers(int,int); //declaring function definition
main()
{
  int n;
  printf("n *** C PROGRAMS BLOG ***");
  printf("n >>> Program to print numbers 1 to n without using Loops <<<");
  printf("nn Enter the value of n: ");
  scanf("%d",&n); //taking value of n as input from user
  print_numbers(1,n); //calling the function
  getch();
}

void print_numbers(int i,int max)
{
 printf("%3dt",i);
   if(i<max)
   {
    //calling function recursively
    print_numbers(++i,max);
   }
   return;
}

Sample Output :

Print 1toN without Loops output

 

Leave a Reply

Your email address will not be published.