Part 1 A palindrome is a number or text phrase that reads the same backward as f
ID: 3557357 • Letter: P
Question
Part 1
A palindrome is a number or text phrase that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 34543 and 11611. Write a program that reads in a five-digit integer and determines whether or not it is a palindrome.
Solving Steps:
Use integer division method (similar to the Excel Assignment Question 4) to solve the problem.
Part 2:
Write a program that checks whether the string given by the user is Palindrome or not.
A string can be said as a Palindrome in the case when you reverse the string and gives the same original string. For example think of a word like ABCCBA:
Original String: ABCCBA
Reverse String: ABCCBA
So both the original and the reverse match each other, so the string is a Palindrome.
In this problem only one word will be used and you need to check whether the word is a palindrome or not. Do not use any built-in functions; use the technique defined below.
How to check whether the string is palindrome or not:
str[0] str1 [1] str1 [2] str1 [3] str1 [4] str1 [5]
A B C C B A
i=0 j=5
Solving Steps:
Compare the character of str[i] and str[j]
Increment i++ (by 1) and Decrement j-- (by1)
Stops when i and j are equal or j<i
Explanation / Answer
part 1
part 2
#include<stdio.h>
#include<string.h>
# define SIZE 26
void main()
{
char s[SIZE];
int flag=0,i,j,l;
printf(" enter the string ");
gets(s);
l=strlen(s);
for
(i=0,j=l-1;s[i]!='';i++,j--)
{
if(s[i]!=s[j])
{
flag=1;
break;
}
}
if(flag==0)
printf(" given string is palindrom");
else
printf(" given string is not palindrom");
}