SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Objective: To examine a user-entered string to determine if it's a palindrome. A palindrome is a
word that is spelled the same forward and backward, such as "radar" or "madam." Your
program should ask the user to enter a word, and then tell the user whether or not that word is a
palindrome. Your program doesn't need to determine whether or not the word is in the English
language. But you can assume that the word is made up of lower-case letters only, and that it is
no more than 20 letters long. So for example your program would determine that the word
"abcdefghijjihgfedcba" is a palindrome. Here is some sample output from the program: Please
enter a word: radar The word you entered, 'radar' is a palindrome. bash-2.04$ a.out Please enter
a word: abccba The word you entered: 'abccba' is a palindrome. bash-2.04$ a.out Please enter a
word: abcddxba The word you entered: 'abcddxba' is not a palindrome. Requirements: Your
program must use at least one function in addition to main. You must use a c-string (null-
terminated character array) to store the word the user enters (as we have been doing all
semester). You are not allowed to use the class "string" in this program. To determine how
many characters are in a c-string, use the strlen function. You will need to "#include ", and then
if you have a c-string called "str" you can store its length in the variable "len" you would
write: "len = strlen(str);" Test your program with all of the above test cases. Save both the
source code and the output it produced after you compiled and ran it. You should save these in a
plain text file with a file extension of either .txt or .cpp. Put comments at the top of your program
with your name, the name of your C++ source file, the name of this assignment and class (CS
110A Lab 5), and a brief description of what the program does. Format it so that it is readable
and professional. Follow the standard conventions for indentation, meaningful variable names,
etc. like the textbook.
Solution
#include<stdio.h>
#include<cstring>
int isPalindrome(char word[])
{
int length,i,j;
length=strlen(word);
i=0;
j=length-1;
while(i<length/2)
{
if(word[i]!=word[j])
return 0;
i++;
j--;
}
return 1;
}
int main()
{
char input_word[21];
printf("Please enter a word:");
scanf("%",input_word);
if(isPalindrome(input_word))
printf("The word you entered,'%' is a palindrome. ",input_word);
else
printf("The word you entered,'%' is not a palindrome. ",input_word);
return 0;
}
Objective- To examine a user-entered string to determine if it-'s a pa.docx

Weitere ähnliche Inhalte

Ähnlich wie Objective- To examine a user-entered string to determine if it-'s a pa.docx

COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxCOMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
donnajames55
 
Hey, I need some help coding this C++ assignment.ObjectivesThis.pdf
Hey, I need some help coding this C++ assignment.ObjectivesThis.pdfHey, I need some help coding this C++ assignment.ObjectivesThis.pdf
Hey, I need some help coding this C++ assignment.ObjectivesThis.pdf
rishabjain5053
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
Adhoura Academy
 

Ähnlich wie Objective- To examine a user-entered string to determine if it-'s a pa.docx (20)

Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
 
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxCOMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
 
Python
PythonPython
Python
 
2019 session 5 describe different basic programming codes and languages
2019 session 5 describe different basic programming codes and languages2019 session 5 describe different basic programming codes and languages
2019 session 5 describe different basic programming codes and languages
 
Learn C# programming - Program Structure & Basic Syntax
Learn C# programming - Program Structure & Basic SyntaxLearn C# programming - Program Structure & Basic Syntax
Learn C# programming - Program Structure & Basic Syntax
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Hey, I need some help coding this C++ assignment.ObjectivesThis.pdf
Hey, I need some help coding this C++ assignment.ObjectivesThis.pdfHey, I need some help coding this C++ assignment.ObjectivesThis.pdf
Hey, I need some help coding this C++ assignment.ObjectivesThis.pdf
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
 
Lecture 0 - CS50's Introduction to Programming with Python.pdf
Lecture 0 - CS50's Introduction to Programming with Python.pdfLecture 0 - CS50's Introduction to Programming with Python.pdf
Lecture 0 - CS50's Introduction to Programming with Python.pdf
 
Csharp_Chap01
Csharp_Chap01Csharp_Chap01
Csharp_Chap01
 
C programming
C programmingC programming
C programming
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
 
Cosc 1436 java programming/tutorialoutlet
Cosc 1436 java programming/tutorialoutletCosc 1436 java programming/tutorialoutlet
Cosc 1436 java programming/tutorialoutlet
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
C programming day#3.
C programming day#3.C programming day#3.
C programming day#3.
 
Chapter3
Chapter3Chapter3
Chapter3
 
Wade not in unknown waters. Part two.
Wade not in unknown waters. Part two.Wade not in unknown waters. Part two.
Wade not in unknown waters. Part two.
 

Mehr von dorisevans99695

A SWOT analysis is conducted during what stage of the HR planning proc.docx
A SWOT analysis is conducted during what stage of the HR planning proc.docxA SWOT analysis is conducted during what stage of the HR planning proc.docx
A SWOT analysis is conducted during what stage of the HR planning proc.docx
dorisevans99695
 

Mehr von dorisevans99695 (20)

A material effect from changing accounting principles should be report.docx
A material effect from changing accounting principles should be report.docxA material effect from changing accounting principles should be report.docx
A material effect from changing accounting principles should be report.docx
 
a system consists of four components connected as shown assume A B C.docx
a system consists of four components connected as shown  assume A B C.docxa system consists of four components connected as shown  assume A B C.docx
a system consists of four components connected as shown assume A B C.docx
 
A SWOT analysis is conducted during what stage of the HR planning proc.docx
A SWOT analysis is conducted during what stage of the HR planning proc.docxA SWOT analysis is conducted during what stage of the HR planning proc.docx
A SWOT analysis is conducted during what stage of the HR planning proc.docx
 
A survey was conducted where people were asked whether they have a pre.docx
A survey was conducted where people were asked whether they have a pre.docxA survey was conducted where people were asked whether they have a pre.docx
A survey was conducted where people were asked whether they have a pre.docx
 
A survey asked what part of the country respondents live in and whethe.docx
A survey asked what part of the country respondents live in and whethe.docxA survey asked what part of the country respondents live in and whethe.docx
A survey asked what part of the country respondents live in and whethe.docx
 
A student is interested in how many dogs were detected with the eDNA s.docx
A student is interested in how many dogs were detected with the eDNA s.docxA student is interested in how many dogs were detected with the eDNA s.docx
A student is interested in how many dogs were detected with the eDNA s.docx
 
A student goes to the library- The probability that she checks out (a).docx
A student goes to the library- The probability that she checks out (a).docxA student goes to the library- The probability that she checks out (a).docx
A student goes to the library- The probability that she checks out (a).docx
 
A stock has a return on equity of 17-5- and a plowback ratio of 35-- W.docx
A stock has a return on equity of 17-5- and a plowback ratio of 35-- W.docxA stock has a return on equity of 17-5- and a plowback ratio of 35-- W.docx
A stock has a return on equity of 17-5- and a plowback ratio of 35-- W.docx
 
A small town collected data on their citizens most frequent mode of tr.docx
A small town collected data on their citizens most frequent mode of tr.docxA small town collected data on their citizens most frequent mode of tr.docx
A small town collected data on their citizens most frequent mode of tr.docx
 
A serious developmental disorder associated with multiple -thalassemia.docx
A serious developmental disorder associated with multiple -thalassemia.docxA serious developmental disorder associated with multiple -thalassemia.docx
A serious developmental disorder associated with multiple -thalassemia.docx
 
A sequence of four tasks is part of the project schedule- Each of the.docx
A sequence of four tasks is part of the project schedule- Each of the.docxA sequence of four tasks is part of the project schedule- Each of the.docx
A sequence of four tasks is part of the project schedule- Each of the.docx
 
A researcher measures a response variable Y and an explanatory variabl.docx
A researcher measures a response variable Y and an explanatory variabl.docxA researcher measures a response variable Y and an explanatory variabl.docx
A researcher measures a response variable Y and an explanatory variabl.docx
 
A protein that evolved to live inside of the membranes of the cell- A-.docx
A protein that evolved to live inside of the membranes of the cell- A-.docxA protein that evolved to live inside of the membranes of the cell- A-.docx
A protein that evolved to live inside of the membranes of the cell- A-.docx
 
A protein that evolved to live in the cytoplasm (or other water locati.docx
A protein that evolved to live in the cytoplasm (or other water locati.docxA protein that evolved to live in the cytoplasm (or other water locati.docx
A protein that evolved to live in the cytoplasm (or other water locati.docx
 
a population has mean u- 13 and standard deviation o-4- what is the z.docx
a population has mean u- 13 and standard deviation o-4- what is the z.docxa population has mean u- 13 and standard deviation o-4- what is the z.docx
a population has mean u- 13 and standard deviation o-4- what is the z.docx
 
A population has a mean -70 and a standard deviation -9- Find the mean.docx
A population has a mean -70 and a standard deviation -9- Find the mean.docxA population has a mean -70 and a standard deviation -9- Find the mean.docx
A population has a mean -70 and a standard deviation -9- Find the mean.docx
 
A person used as an example for other employees to show the best in de.docx
A person used as an example for other employees to show the best in de.docxA person used as an example for other employees to show the best in de.docx
A person used as an example for other employees to show the best in de.docx
 
A patient recently received a diagnostic tap for a large pleural effus.docx
A patient recently received a diagnostic tap for a large pleural effus.docxA patient recently received a diagnostic tap for a large pleural effus.docx
A patient recently received a diagnostic tap for a large pleural effus.docx
 
A patient has newborn twins- One is healthy- with natural color to li.docx
A patient has newborn twins-  One is healthy- with natural color to li.docxA patient has newborn twins-  One is healthy- with natural color to li.docx
A patient has newborn twins- One is healthy- with natural color to li.docx
 
A partner has a capital balance of $40000 Jenuary to April $50-000 tro.docx
A partner has a capital balance of $40000 Jenuary to April $50-000 tro.docxA partner has a capital balance of $40000 Jenuary to April $50-000 tro.docx
A partner has a capital balance of $40000 Jenuary to April $50-000 tro.docx
 

Kürzlich hochgeladen

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Kürzlich hochgeladen (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Objective- To examine a user-entered string to determine if it-'s a pa.docx

  • 1. Objective: To examine a user-entered string to determine if it's a palindrome. A palindrome is a word that is spelled the same forward and backward, such as "radar" or "madam." Your program should ask the user to enter a word, and then tell the user whether or not that word is a palindrome. Your program doesn't need to determine whether or not the word is in the English language. But you can assume that the word is made up of lower-case letters only, and that it is no more than 20 letters long. So for example your program would determine that the word "abcdefghijjihgfedcba" is a palindrome. Here is some sample output from the program: Please enter a word: radar The word you entered, 'radar' is a palindrome. bash-2.04$ a.out Please enter a word: abccba The word you entered: 'abccba' is a palindrome. bash-2.04$ a.out Please enter a word: abcddxba The word you entered: 'abcddxba' is not a palindrome. Requirements: Your program must use at least one function in addition to main. You must use a c-string (null- terminated character array) to store the word the user enters (as we have been doing all semester). You are not allowed to use the class "string" in this program. To determine how many characters are in a c-string, use the strlen function. You will need to "#include ", and then if you have a c-string called "str" you can store its length in the variable "len" you would write: "len = strlen(str);" Test your program with all of the above test cases. Save both the source code and the output it produced after you compiled and ran it. You should save these in a plain text file with a file extension of either .txt or .cpp. Put comments at the top of your program with your name, the name of your C++ source file, the name of this assignment and class (CS 110A Lab 5), and a brief description of what the program does. Format it so that it is readable and professional. Follow the standard conventions for indentation, meaningful variable names, etc. like the textbook. Solution #include<stdio.h> #include<cstring> int isPalindrome(char word[]) { int length,i,j; length=strlen(word);
  • 2. i=0; j=length-1; while(i<length/2) { if(word[i]!=word[j]) return 0; i++; j--; } return 1; } int main() { char input_word[21]; printf("Please enter a word:"); scanf("%",input_word); if(isPalindrome(input_word)) printf("The word you entered,'%' is a palindrome. ",input_word); else printf("The word you entered,'%' is not a palindrome. ",input_word); return 0; }