C Program to print all natural number between given interval using recursion

Category: C Program

C Program to print all natural number between given interval using recursion

C Program to print all natural number between given interval using recursion

#include <stdio.h>

void printNumbers(int, int);

void main()
{
    int start, end;

    printf("Enter the number to start: ");
    scanf("%d", &start);
    printf("Enter the number to end: ");
    scanf("%d", &end);

    printNumbers(start, end);
}

void printNumbers(int start, int end)
{
    if (start > end)
        return;
    printf("%d\t", start);

    printNumbers(start+1, end);
}

Output

Enter the number to start: 5

Enter the number to end: 50

5       6       7       8       9       10      11      12      13      14      15

16      17      18      19      20      21      22      23      24       25      26

27      28      29      30      31      32      33      34      35      36      37

38      39      40      41      42      43       44      45      46      47      48

49      50

Recommended Posts