1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olganol [36]
3 years ago
6

Write a C++ program that determines if a given string is a palindrome. A palindrome is a word or phrase that reads the same back

ward as forward. Blank, punctuation marks and capitalization do not count in determining palindromes. Here is some examples of palindromes:
Radar
Too hot to hoot
Madam!I'm adam
Computers and Technology
1 answer:
Ostrovityanka [42]3 years ago
6 0

The cpp program to determine if the given string is palindrome, is shown below.

The program has comments at places to indicate the logic.

#include <iostream>

#include <string.h>

using namespace std;

int main() {

// string is taken as an array of characters of size 50

char str1[50];

int i, len, flag;

cout<<"Enter any string to check for palindrome"<<endl;

cin>>str1;

// length of input string is stored in variable len to be used in the loop

len = strlen(str1)-1;

for(i=0; i<=len; i++)

{

// if string is palindrome, value of flag variable is initialized to 0 else 1

   if(str1[i]==str1[len-i])

        flag = 0;

           else

                flag = 1;

}

if (flag == 0)

       cout << str1 << " is a palindrome";

   else

       cout << str1 << " is not a palindrome";      

// returns integer value since main has return type of integer  

   return 0;

}

Explanation:

The header files for input and output and string are imported.

#include <iostream>

#include <string.h>

The string is taken as an array of type char having adequate size of 50.

char str1[50];

The length of the input string is calculated as

len = strlen(str1)-1;

Within a single for loop using a single variable and the length of the string, we check whether the string is palindrome or not.

      for(i=0; i<=len; i++)

{

   if(str1[i]==str1[len-i])

        flag = 0;

            else

                flag = 1;

}

The int flag is declared but not initialized.

If the string is palindrome, the value of flag variable becomes 0. Otherwise, the value of flag variable will be initialized to 1.

Depending on the value of flag variable, the message is displayed if the input string is palindrome or not.

The above program works for all strings irrespective of special characters which may be included in the string.

The above program also works for the examples of input string given in the question.

You might be interested in
HELP ME PLEASE !!!!!!!!!!
Snezhnost [94]

Answer:

the last one

Explanation:

8 0
3 years ago
What is the difference between an html opening tag and a closing tag?.
Doss [256]

Answer:

Explanation:

Generally speaking, there are two kinds of tags - opening tags: <html> and closing tags: </html>. The only difference between an opening tag and a closing tag is the forward slash "/". You label content by putting it between an opening tag and a closing tag.

HTML is all about elements.

7 0
1 year ago
Sergio knows that to meet the project requirements, it is essential to have
zhenek [66]

Answer:

I need a better explanation??

4 0
3 years ago
A new folder can be created by
user100 [1]

Answer:

The fastest way to create a new folder in Windows is with the CTRL+Shift+N shortcut. 1. Navigate to the location where you want to create the folder. You can create a new folder at any location on your hard drive or within another folder (creating a subfolder) in File Explorer.[/tex]

5 0
2 years ago
Read 2 more answers
What is a possible explanation for the issue described below? A user reports that ever since she or he began creating animations
Marat540 [252]
VRAM because VRAM is used for graphic intensive workloads
8 0
3 years ago
Read 2 more answers
Other questions:
  • Which graphic design tool allows you to lay images on top of one another? A. Layers B. Selection C. Drawing D. Color
    10·2 answers
  • Why is color theory important
    6·2 answers
  • printLarger is a method that accepts two int arguments and returns no value. Two int variables, sales1 and sales2, have already
    11·1 answer
  • What is the difference between a design pattern and a DLL?
    12·1 answer
  • Ethics is a way of behaving so that you are
    7·2 answers
  • Coordinate with
    12·1 answer
  • Create a function names minElement() that takes an array of numbers as a paaramter and returns the min value of the array. The a
    9·1 answer
  • Rita tried unsuccessfully to open a PDF file attachment in her Inbox by double-clicking the attachment in the Reading Pane. What
    8·1 answer
  • Which of the following is true about overloaded methods?
    6·1 answer
  • A trace table is used for
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!