C Program To Print 1 to N in Ascending Order Using Recursion


♣ Try it Out ::
#include<stdio.h>
#include<conio.h>

AscendingOrder(int n)
{
    if(n == 0) return;

    AscendingOrder(n-1);
    printf("%d ", n);
}

main()
{
    int N;

    printf("Enter the n'th number: ");
    scanf("%d", &N);

    printf("Numbers from 1 to %d in ascending order: \n", N);
    AscendingOrder(N);

    getch();
    return(0);
}

♣ Output ::
Enter the n'th number: 15
Numbers from 1 to 15 in ascending order:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

♣ Downloads ::

Comments

Popular posts from this blog

C++ :: Topological Sort Algorithm (using DFS)

How to Hack Facebook Account

C++ :: Strongly Connected Components Algorithm (SCC)