-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchararray.cpp
More file actions
62 lines (51 loc) · 1.07 KB
/
Copy pathchararray.cpp
File metadata and controls
62 lines (51 loc) · 1.07 KB
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
57
58
59
60
61
62
#include<iostream>
using namespace std;
//checking for palindrome or not
bool checkPalindrome(char name[] , int n){
int s=0;
int e=n-1;
while(s<e){
if(name[s] != name[e]){
return 0;
}else{
s++;
e--;
};
}
return 1;
}
//reversing the arr
void reverse(char arr[] ,int n){
int s=0;
int e= n-1;
while(s<e){
swap(arr[s++] , arr[e--]);
}
}
//getting the length of the character array
int getLength(char arr[]){
int count =0;
for(int i=0; arr[i] != 0 ; i++){
count++;
}
return count;
}
int main(){
char name[20];
cout<<"Enter your name: "<<endl;
cin>>name;
// name[2] = '\0';
cout<<"Your name is:- "<<name<<endl;
int len = getLength(name);
cout<<"Length of your char array is:- "<< len <<endl;
reverse(name, len);
cout<<"Your name is:- "<<name<<endl;
cout<<"Palindrome:- ";
if (checkPalindrome(name , len)==1)
{
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
return 0;
}