-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringchar.cpp
More file actions
36 lines (30 loc) · 790 Bytes
/
Copy pathstringchar.cpp
File metadata and controls
36 lines (30 loc) · 790 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
#include<iostream>
#include<cstring> // for strlen
using namespace std;
void reverse(char arr[], int n){
int s = 0;
int e = n - 1;
while(s < e){
swap(arr[s], arr[e]);
s++;
e--;
}
}
int getlenght(char arr[]){
int count=0;
for(int i=0; arr[i]!='\0'; i++){
count++;
}
return count;
}
int main(){
char name[20];
cout << "Enter name: ";
cin >> name;
int length = strlen(name); // Get the actual length of the input string
cout << "Your name is " << name << endl;
reverse(name, length); // Reverse the actual characters in the name
cout << "Reversed name is " << name << endl;
cout<<"lenght of string is "<<getlenght(name);
return 0;
}