We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent db94823 commit 64a0aefCopy full SHA for 64a0aef
reverse-string.cpp
@@ -0,0 +1,32 @@
1
+// C++ program to demonstrate how to reverse a string accepted from a user using character array
2
+
3
+#include <iostream>
4
+using namespace std;
5
+void reverse(char [], int);
6
+int main()
7
+{
8
+ char str[15]; int i = -1;
9
10
+ do {
11
+ i++;
12
+ str[i] = getchar();
13
+ } while (str[i] != '\n' && i<14);
14
15
+ int length = i;
16
+ reverse(str, length);
17
18
+ for (int j = 0; j < length; j++) {
19
+ cout << str[j];
20
+ }
21
+ return 0;
22
+}
23
+void reverse(char arr[], int size) {
24
+ int start = 0, end = size - 1;
25
+ while (start < end) {
26
+ char temp = arr[start];
27
+ arr[start] = arr[end];
28
+ arr[end] = temp;
29
+ start++;
30
+ end--;
31
32
0 commit comments