ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I already did overall coding for this question but i don't understand last statement saying [Enter a five-digit number ( -1 to end ): -1].Can anyone plz tell me and edit my coding for me plz.Thanks alot for your help.
Code:
#include <stdio.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
main () {
char str[30];
int isPalindrome = TRUE;
int i,j;
printf("Enter a five-digit number : ");
gets(str);
j = strlen(str) - 1;
i = 0;
while(i <= j && isPalindrome) {
if(str[i] != str[j]) {
isPalindrome = FALSE;
}
i++;
j--;
}
if(isPalindrome) {
printf("%s is a palindrome!\n", str);
}
else {
printf("%s is not a palindrome\n", str);
}
return 0;
}
Question 1
A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a program that reads in a five-digit integer and determines whether or not it is a palindrome. [HINT: Use the division and remainder operators to separate the number into its individual digits.]
(5 marks)
Sample output:
Enter a five-digit number ( -1 to end ): 18181
18181 is a palindrome
Enter a five-digit number ( -1 to end ): 16738
16738 is not a palindrome
Seeing as you've already written some code.. I think the Sample output implies (!) that your prog should be an infinite loop that repeatedly asks for a number to test, and only exits if you give it the value '-1' to test.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.