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
Given a line of text as input, output the number of characters excluding spaces, periods, or commas. If the input is:
enot [183]

In python 3.8:

print(len([x for x in input("Enter your text: ") if x not in "., "]))

I hope this helps!

3 0
3 years ago
Which invention provided instant communication and information to a massive audience for the first time?
igor_vitrenko [27]
B. Television. It provided <span>instant communication and information to a massive audience for the first time in 1927.

Hope this helps :)</span>
4 0
3 years ago
Read 2 more answers
Using selection sort, how many times longer will sorting a list of 40 elements take compared to a list of 5 elements
Hoochie [10]

It will take 8 times more time to sort a 40-element list compared to the time spent on a 5-element list.

We can arrive at this answer as follows:

  • We can see that if we divide a group of 40 elements into groups containing 5 elements, we will have 8 groups.
  • In this case, the time it would take to sort the list of one group of 5 elements would be repeated 8 times so that we could sort all the groups and their elements.

Another way to do this is to divide the number 40 by 5. We would have the number 8 as a result, which indicates that we would need 8 times more time to sort a list of 40 elements, compared to a list of 5 elements.

You can get more information about lists at this link:

brainly.com/question/4757050

5 0
2 years ago
Advertising andpublicity are used to:
WINSTONCH [101]

Answer:

d. All of the given options

Explanation:

Great question, it is always good to ask away and get rid of any doubts that you may be having.

<u>Advertising and Publicity</u> is used for many reasons.

Retail Companies use advertising and publicity to promote their products and in term increase sales of that product when it hits the shelves.

Meanwhile, other companies such as Law Firms use advertising and publicity create awareness for their law firm and communicate with customers over high profile case etc.

Therefore, the answer is all of the above.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

5 0
3 years ago
I know this is not a school type question but i really need some help.
pashok25 [27]
If I'm not mistaken u can't do that but u can go in your settings if u have an iPhone and add that email with your main one.
8 0
3 years ago
Other questions:
  • A computer which links several pcs together in a network is called
    10·1 answer
  • Match each logical function with its description. AND COUNTIF SUMIF IF tests for a certain condition and returns one of two valu
    7·1 answer
  • What OS has a large market share but is limited because it can be installed only on one particular brand?
    8·2 answers
  • Is printer an input device​
    5·1 answer
  • .____________ is a way to identify and differentiate goods andservices through use of a name or distinctive design element.
    10·1 answer
  • 1. Which of the following is not related to a buffer overflow? A. Static buffer overflow B. Index error C. Canonicalization erro
    10·1 answer
  • Please debug the below code in Java please.
    15·1 answer
  • Mobile devices have their own OSs, tailored to their handheld needs, which means they are not immune to what?
    14·1 answer
  • HELP FAST PLEASE
    6·1 answer
  • Levi wants to run 5 commands sequentially, but does not want to create a shell script. He knows that each command is going to ta
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!