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
- Program in C and C++ to print reverse of a given number using recursive function
- Program in c++ to find the reverse of a given number
- Program in C to reverse given number
- Program in C to print reverse of a given number in different ways (100 rev 001)
- Program in C++ to reverse a given string
- Program in C to reverse the given string.
- Program in C++ to create function in String class to find reverse of given string
- Program in C to check the given string is palindrome or not.
- Program in C and C++ to print reverse of a given string using recursive function
0 Comments