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 reverse of a given string using recursive function


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  


Post a Comment

0 Comments