This website completely moved to new platform. For latest content, visit www.programmingposts.com

Search this Site

12 May 2013

C PROGRAM TO PRINT NUMBERS 1 TO N WITHOUT USING LOOPS

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("\n\n 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("%3d\t",i);
if(i<max)
{
    //calling function recursively
print_numbers(++i,max);
}
return;
}

Sample Output :