Like Tree2Likes
  • 2 Post By claudiu

Palindrome checker for numbers

This is a discussion on Palindrome checker for numbers within the C Programming forums, part of the General Programming Boards category; I have read a lot of topics about this problem. So: Code: #include <stdio.h> int main(){ int number,temp,remainder,sum=0; printf("Input a ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    1

    Palindrome checker for numbers

    I have read a lot of topics about this problem.
    So:

    Code:
    #include <stdio.h>
    
    int main(){
      int number,temp,remainder,sum=0;
    
      printf("Input a number:\n");
      scanf("%d",&number);
      temp = number;
    
      while(number>0)
        {
          remainder=number%10; //Gets Last Digit
          number/=10;          //Truncates Last Digit
          sum=sum*10 + remainder; //Builds value of reversed number
         }
    
       if (sum==temp)
         printf ("\nThe Number Is A Palindrome ");
       else
         printf ("\nThe Number Is Not A Palindrome ");
    
       getch ();
       return 0;
    
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Is there a question in there some place?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    I seem to remember an ACM competition problem within the realm of your... statement. But, again, you have not asked a question.
    -- Will you show me how to c++?

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by Ákos Kovács View Post
    I have read a lot of topics about this problem.
    Well done.
    AndrewHunter and iMalc like this.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. spelling checker
    By Tom.b in forum C Programming
    Replies: 8
    Last Post: 11-12-2009, 11:17 PM
  2. Spell Checker
    By DeepFyre in forum Tech Board
    Replies: 2
    Last Post: 02-11-2005, 12:17 PM
  3. URL checker
    By bigSteve in forum C++ Programming
    Replies: 10
    Last Post: 05-24-2004, 05:48 PM
  4. spell checker in c needs help
    By madmax in forum C Programming
    Replies: 3
    Last Post: 03-13-2003, 09:36 AM
  5. spell checker
    By bob20 in forum Windows Programming
    Replies: 3
    Last Post: 12-03-2002, 02:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21