Program in C and C++ to print reverse of a given string using recursive function
C Program
#include<stdio.h> //reverse string using recursive function void revstr(char *str, int n){ if(str[n] == '\0') return; revstr(str, n + 1); printf("%c",str[n]); } int main() { char str[100]; printf("Enter a string:- "); scanf("%s",str); printf("Reverse : "); revstr(str,0); return 0; }
C++ Program
#include<iostream> using namespace std; //reverse string using recursive function void revstr(char *str, int n){ if(str[n] == '\0') return; revstr(str, n + 1); printf("%c",str[n]); } int main() { char str[100]; cout<<"Enter a string :- "; cin>>str; cout<<"Reverse : "; revstr(str,0); 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.
0 Comments