-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathReverse_String_Recursion.c
56 lines (49 loc) · 1.85 KB
/
Reverse_String_Recursion.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Program to input an string to obtain the reversal string and it's length using recursion.
*/
#include<stdio.h>
#include<string.h>
void org_str(char *str);
void rev_str(char *str);
int length(char *str);
void org_str(char *str )
{
if(*str == '\0')
return;
putchar(*str );
org_str(str+1);
}
void rev_str(char *str )
{
if(*str == '\0')
return;
rev_str(str+1);
putchar(*str );
}
main( )
{
char str[100];
printf("Enter the string : \n");
gets(str);
printf("Your entered string is : \n");
org_str( str );
printf("\n");
printf("The reversed string is : \n");
rev_str(str);
printf("\n");
printf("The length of the string is : \n");
printf("%d",strlen(str));
printf("\n");
}
/*
Enter the string :
string
Your entered string is :
string
The reversed string is :
gnirts
The length of the string is :
6
Time Complexity : O(n)
Space Complexity : o(1)
*/