Write a program, which takes an array of characters from users. Your task is to check either it is palindrome or not.
Note: Palindrome is a string that reads the same from both ends. i.e. bob, mom, dad, civic.
#include<iostream>
using namespace std;
void palindromTest(char array[],int n){
int flag=0;
for(int k=0;k<=n/2&&n!=0;k++){
if(array[k]!=array[n-k-1]){
flag=1;
break;
}
if (flag == 1)
cout << "Not Palindrome";
else
cout << "Palindrome";
}
}
int main(){
int n;
char array[n];
cout<<"Number of elements are present in the array:\n"<<endl;
cin>>n;
cout<<"\n Total number of elements present in the array\n"<<n<<endl;
cout<<"Please enter the letters of english word(english word)"<<endl;
for (int i = 0; i < n; i++) {
cin >> array[n];
}
cout << "The entered word is: ";
for (int j = 0; j < n; ++j) {
cout <<array[n];
}
palindromTest(array,n);
return 0;
}
Comments
Leave a comment