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
which process consists of one application program following a logical access path (lap) and then a dbms following a physical acc
laiz [17]

A DBMS acts as a conduit between the database and the applications that will use it, enabling users to access, modify, and control how the data is arranged and optimized.

Data points that are connected to one another are stored and accessible in a relational database, which is a form of database. The relational model, an easy-to-understand method of representing data in tables, is the foundation of relational databases. Data items are requested from the database by application programs, which are created using a combination of the DBMS's data manipulation language and a traditional programming language. The DBMS locates and provides the data elements requested by the application programs.

Learn more about database here-

brainly.com/question/6447559

#SPJ4

5 0
1 year ago
Go to the Creamy Ice Corporation passage on the next page. Insert the trademark sign after the word “Corporation'' in the first
GuDViN [60]

Answer:

v

Explanation:

because it is

5 0
3 years ago
Everybody at a company is assigned a unique 9 digit ID. How many unique IDs exist?
timama [110]

Answer:

3,265,920 unique ID exist.

Explanation:

The nine digits are from 0 to 9, there are ten bits from 0 -9,

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

The first is select from the highest bit (9), and the second is selected at random from 0 - 9, the third bit to the last must be unique and different from each other;

number of unique IDs = 9 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2

Multiplying the nine bits of unique IDs = 3,265,920.

3 0
3 years ago
ASAP HELP
vovangra [49]

Answer:@the bottom slide

Explanation:wats ya email i

will help u

8 0
3 years ago
What are strategies that you can use to yield web sites that are relevant to your research topic?
evablogger [386]

Answer: PLEASE MARK BRAINELEIST

Locating Useful Resources

When you chose a paper topic and determined your research questions, you conducted preliminary research to stimulate your thinking. Your research proposal included some general ideas for how to go about your research—for instance, interviewing an expert in the field or analyzing the content of popular magazines. You may even have identified a few potential sources. Now it is time to conduct a more focused, systematic search for informative primary and secondary sources.

5 0
3 years ago
Other questions:
  • CAD helps professionals to _____. create a technical drawing give directions to a new location calculate the interest rate of a
    13·2 answers
  • Which one of these do not belong on the Do's list in Helpful Hints when preparing a presentation: Which one of these do not belo
    8·1 answer
  • I know how to design it but I’m confused as to how to write a function code based on the info provided.
    10·1 answer
  • A single-user database system automatically ensures ____ of the database, because only one transaction is executed at a time.
    13·1 answer
  • Mary can view the thumbnails of her presentation slides when she’s creating the slides which element of the programs interface i
    8·1 answer
  • Erewrxdnnefwn q wedsvd
    6·1 answer
  • Mention two strategies of collecting data​
    13·1 answer
  • Lin wants to play an online game with her friends. She read the description of the game and knows it contains several features w
    12·1 answer
  • What is the difference between RELIABLE and UNRELIABLE sources of<br> income?
    7·2 answers
  • Given positive integer n, write a for loop that outputs the even numbers from n down to 0. If n is odd, start with the next lowe
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!