Monday, 19 September 2016

DS-LAB(PALINDROME_STRING)-EXPERIMENT-8

Detailed Algorithm:
Step 1:  Input S (string)
Step 2:  Len = 0 , Flag =0
Step 3:  While (S[Len] != NULL)
                        Len++
Step 4:  I = 0 , J = Len-1
Step 5:  While ( I < (Len/2)+1 )
                        If ( S[I] == S[J] )
                                 Flag=0
                        else
                                  Flag=1
                        I++ , J–
Step 6:      If ( Flag == 0 )
                               Print Key Is a Palindrome
                     else
                                Print Key Is Not a Palindrome
Step 7: End
 Flowchart:-
FlowChart_Palindrome

PROG

#include<iostream> using namespace std; int main(){ char string1[20]; int i, length; int flag = 0; cout << "Enter a string: "; cin >> string1; length = strlen(string1); for(i=0;i < length ;i++){ if(string1[i] != string1[length-i-1]){ flag = 1; break; } } if (flag) { cout << string1 << " is not a palindrome" << endl; } else { cout << string1 << " is a palindrome" << endl; } system("pause"); return 0; }

No comments:

Post a Comment