-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_reverse.c
More file actions
47 lines (43 loc) · 954 Bytes
/
Copy pathstring_reverse.c
File metadata and controls
47 lines (43 loc) · 954 Bytes
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
//wap to reverse the string using recursive concept
//using recursive concept
//find the length of string and reversing the string
#include<stdio.h>
int string_length(char a[],int index);
void string_reverse(char [],int index, int length);
int main()
{
char a[10];
int length,index=0;
printf("enter the string\n");
scanf("%s",a);
length=string_length(a,index);
printf("length of string is %d\n",length);
string_reverse(a,index,length-1);
printf("after reversing the string %s\n",a);
}
//function body
//find the length of string using recursive concept
int string_length(char a[],int index)
{
static int count=0;
if(a[index])
{
count++;
string_length(a,index+1);
}
else
return count;
}
//function for reversing the string
void string_reverse(char a[],int index,int length)
{
char temp;
temp=a[index];
a[index]=a[length-index];
a[length-index]=temp;
if(index==length/2)
{
return;
}
string_reverse(a,index+1,length);
}