C PROGRAM TO PRINT NUMBERS 1 TO N WITHOUT USING LOOPS
C PROGRAM TO PRINT NUMBERS 1 TO N WITHOUT USING LOOPS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#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 :