-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
54 lines (41 loc) · 885 Bytes
/
Copy pathmain.c
File metadata and controls
54 lines (41 loc) · 885 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
47
48
49
50
51
52
53
54
#include <stdio.h>
void swap_chars(char* arr, int a, int b)
{
arr[a] += arr[b];
arr[b] = arr[a] - arr[b];
arr[a] -= arr[b];
}
void reverse_sub(char* arr, int start, int end)
{
for (int i = 0; i < end-start-i; i++)
{
swap_chars(arr, start+i, end-i);
// arr[start+i] += arr[end-i];
// arr[end-i] = arr[start+i] - arr[end-i];
// arr[start+i] -= arr[end-i];
}
}
void reverse(char* arr, int size)
{
reverse_sub(arr, 0, size-1);
arr[size] = '\0';
}
int main()
{
char arr1[] = "abcdefghi";
printf("%s\t", arr1);
reverse(arr1, 9);
printf("%s\n", arr1);
char arr2[] = "Hello World!";
printf("%s\t", arr2);
reverse(arr2, 12);
printf("%s\n", arr2);
char arr3[] = "This word is reversed";
printf("%s\t", arr3);
reverse_sub(arr3, 5, 8);
printf("%s\n", arr3);
char arr4[] = "abcdefg";
printf("%s\t", arr4);
swap_chars(arr4, 0, 6);
printf("%s\n", arr4);
}