/re_StrRev.c Secret
Created
December 17, 2017 03:36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Aim: Write a function which displays a string in reverse order (Use Recursion)*/ | |
#include<stdio.h> | |
#include<string.h> | |
#define size 100 | |
void re_StrRev(char str[],int i); // re_StrRev Function Prototype | |
void main() | |
{ | |
char str[size]; | |
printf("\n Enter any string:-"); | |
scanf("%s",str); | |
printf("\n"); | |
re_StrRev(str,strlen(str)-1); | |
printf("\n \n"); | |
} // End of main | |
// re_StrRev Function | |
void re_StrRev(char str[],int i) | |
{ | |
if(i>=0) | |
{ | |
printf("%c",str[i]); | |
re_StrRev(str,i-1); | |
} | |
} // End of re_StrRev Function | |
/* Ouput of above code:- | |
[root@localhost Computer Science C]# cc e12b3.c | |
[root@localhost Computer Science C]# ./a.out | |
Enter any string:-Halo | |
olaH | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment