adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C and C++ to print Nth natural numbers in reverse order using recursive function


Program in C and C++ to print Nth natural numbers in reverse order using recursive function

C Program
#include<stdio.h>
//print nth natural numbers in reverse order
 void printNthRev(int n){
    if(n == 0)
        return;
    printf("%d ",n);
    printNthRev(n - 1);
 }
 int main()
  {
    int n;
    printf("Enter a number :- ");
    scanf("%d",&n);
    printf("%d natural numbers in reverse order \n",n);
    printNthRev(n);
    return 0;
  }
C++ Program
#include<iostream>
 using namespace std;
//print nth natural numbers in reverse order
 void printNthRev(int n){
    if(n == 0)
        return;
    printf("%d ",n);
    printNthRev(n - 1);
 }
 int main()
  {
    int n;
    cout<<"Enter a number :- ";
    cin>>n;
    cout<<n<<" natural numbers in reverse order \n";
    printNthRev(n);
    return 0;
  }
Output :-










Related Programs



Post a Comment

0 Comments