Question 1: Write a C++ program that takes input of a string and check if the string is  palindrome or not. 

February 13, 2019
Question 1: Write a C++ program that takes input of a string and check if the string is  palindrome or not.



/*
Name:                   Mudassar Ali
Roll:                   BCSF15M045   [Morning]
Assignment:             No# 05
Teacher:                Miss Sadia Shahzad
*/

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    cout<<"\tThis Programme will check the string is palindrome or not!!\n\n";

     char str  [50]={0};       // Storing the input string
     bool flag = true;         // bool function used to ensure flag = 1;
     cout<<"Enter the string:";
     cin>>str;
     int len =strlen(str);     // strlen() function is used to calculate string  length.
     for(int i = 0; i<len;i++) // Iterate the string till i<len becomes fail.
     {
         if(str[i]!= str[len-i-1])  // To check the 0 th  index is equal with ith index and vice versa.
          flag = false;             // if condition becomes does not equal to 0 th with ith then loop will terminate.
          break;
     }
     if (flag)                // If flag = 1  then it will be a palindrome string.....
       cout<<"\n"<<str<<" :It is a Palindrome String\n";
     else
       cout<<"\n"<<str<<": It is not a Palindrome String";
return 0;
}

No comments:

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();
Powered by Blogger.