Thread: palindrome programs

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    28

    palindrome programs

    i need to wirte a program for a class and i have absolutley no idea as how to do it can you help me out. these are the requirement:Write a program to check if a given positive integer is a palindrome or not. A palindrome number is one that read the same forward and backwards. Your program MUST use while statements only.
    Last edited by rambos; 02-28-2008 at 04:29 PM.

  2. #2
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    No it will not be possible to get your program written, with someone explaining it.
    We can guide you though through your attempts to write it using C.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  3. #3
    Programmer in Training TWIXMIX's Avatar
    Join Date
    Feb 2004
    Posts
    57
    I'd probably give a stack of try, read up on it if you don't know how to implement them.

    They work on a last in last out basis so just do checks that way. It's actually a pretty simple problem once you understand stacks.

    This might break the whole while statement though. SO I'm sure the guy above me's response will work.
    Learning C++
    Programmer in training

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    5
    stack what is a stack?
    Whats it have to do with while statements

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > stack what is a stack?
    http://www.nist.gov/dads/HTML/stack.html

  6. #6
    abyss - deep C
    Join Date
    Oct 2007
    Posts
    46
    one way to find out is to reverse the number and check if the resulting number is equal to the original number.

    Code:
    initialize r_num to 0
    while num is positive
           multiply r_num by 10 and add last digit of num to it
           discard the last digit of num
    cheers
    maverix

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    5
    how would you use that in a while statement.
    If while is while(x>0).
    with the double remainder value.

  8. #8
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Try this!!
    Code:
    #include <stdio.h>
    #include <string.h>
    main(){
    	int thenumber=12343231;
    	char numbuf[100];
    	int numlen;
    	int offset=0;
    	int result=0;
    		sprintf(numbuf,"%d",thenumber);
    		numlen=strlen(numbuf);
    		while(offset<numlen-offset){
    			if (numbuf[offset]!=numbuf[numlen-offset-1]){ result=1;break;}
    			offset++;
    		}
    		if (result==0) printf("\nPalindrome");
    		else printf("\nNot Palindrome");
    }

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    66
    While statements only right? Try this..

    Code:
    #include<stdio.h>
    
    int main() {
        char number[9];
        char temp[9];
        int i = 0,j = 0,flag;
        printf("Enter a number : ");
        scanf("%9[^\n]",number);
        
        while(number[i]!='\0') i++;
        temp[i--] = '\0';
        
        while(i+1) temp[i--] = number[j++];
            
        while(temp[i]!='\0') {
            flag = temp[i]!=number[i++]? 1 : 0;
        }
        
        flag? puts("Not a palindrome") : puts("Palindrome");
        return 0;   
    }

  10. #10
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Try submitting this and let us know the results.

    Code:
    #while <while.h>
    #while <while.h>
    while(){
    	while while=while;
    	while while[while];
    	while while;
    	while while=while;
    	while while=while;
    		while(while,"while",while);
    		while=while(while);
    		while(while<while-while){
    			while (while[while]!=while[while-while-while]){ while=while;while;}
    			while++;
    		}
    		while (while==while) while("\nwhile");
    		while while("\nwhile while");
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in Recursive String Palindrome Code
    By clegs in forum C Programming
    Replies: 13
    Last Post: 12-21-2008, 12:36 PM
  2. bool palindrome definition
    By justinc911 in forum C++ Programming
    Replies: 3
    Last Post: 11-26-2003, 05:50 PM
  3. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  4. Palindrome Coding trouble
    By TheLoneWolf32 in forum C++ Programming
    Replies: 3
    Last Post: 02-22-2003, 07:05 PM
  5. palindrome HELP !!!
    By TED22_8 in forum C Programming
    Replies: 23
    Last Post: 01-22-2002, 02:14 PM