Thread: Palindrome Calculator

  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    7

    Palindrome Calculator

    I was wondering what was wrong with my program, it goes through multiplying 99 by 99-1 and is supposed to say if the number is a palindrome; however, every number is said its not, even numbers that are palindromes. Any help would be appreciated.

    #include <stdio.h>
    #include <stdlib.h>




    int main()
    {
    int a, b, reverse = 0, c = 99, d = 99;
    while (d != 0)
    {
    a = c*d;
    b = a;
    while (b != 0)
    {
    reverse = reverse * 10;
    reverse = reverse + b % 10;
    b /= 10;
    }
    if (a == reverse)
    printf("%d Yes.\n", a);
    else
    printf("%d No.\n", a);
    if (d > 0)
    --d;
    }



    system("pause");
    return 0;
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,616
    Have you tried printing reverse to see what you come up with?
    Last edited by whiteflags; 01-12-2016 at 05:49 PM.

  3. #3
    Registered User
    Join Date
    Jan 2016
    Posts
    7
    Yeah that seems to be the issue, the value of reverse is not even remotely close to the original number, do you have any idea why? It works fine without the multiplication part.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,508
    Please be sure to use code tags when posting code.

    Before you perform new operations on the variable "reverse", you might want to reset it back to zero.

  5. #5
    Registered User
    Join Date
    Jan 2016
    Posts
    7
    Yup that was my problem, such a silly mistake. Thanks.

  6. #6
    Registered User
    Join Date
    Sep 2010
    Location
    Europe
    Posts
    87
    And when people here use code tags, it is so cool to have a nice indent style.

    https://en.wikipedia.org/wiki/Indent_style

    Reverse numbers were also discussed recently:

    Reverse of a number
    Last edited by nerio; 01-12-2016 at 08:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Palindrome C++
    By GrafixFairy in forum C++ Programming
    Replies: 2
    Last Post: 04-28-2014, 08:53 AM
  2. Palindrome C++
    By GrafixFairy in forum C++ Programming
    Replies: 4
    Last Post: 04-07-2014, 01:14 AM
  3. Is it a Palindrome?
    By xp5 in forum C Programming
    Replies: 3
    Last Post: 09-06-2007, 05:26 AM
  4. palindrome
    By chodmama in forum C Programming
    Replies: 1
    Last Post: 02-20-2006, 02:52 AM
  5. Palindrome
    By Ginny Morgan in forum C Programming
    Replies: 7
    Last Post: 05-08-2003, 04:04 PM

Tags for this Thread