Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts

    palindrome programme

    hi all,
    does anyone have a sample of a palindrome programme? or can someone advice me on how to write one?...thanks a million...
    Warm Regards,
    Mivec

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    256
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you trying to confirm or generate palindromes?

  • #3
    New Coder
    Join Date
    Jan 2005
    Location
    INDIA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    to check for palindrome

    its very easy to check for palindromes.
    just a few lines of code in c/c++

    here's a sample ( if u want to check for palindromes ) :::

    #include<stdio.h>
    #include<conio.h>
    #include<strings.h>

    void main()
    {
    char* str_in;
    char* str_rev;

    clrscr();

    printf("\n Enter the String to be checked :: ");
    scanf("%s",str_in);

    str_rev=strrev(str_in);

    if(strcmp(str_in,str_rev)==0)
    {
    printf("\n String entered is a palindrome");
    }
    else
    {
    printf("\n String entered is not a palindrome");
    }

    getch();
    }

    strrev() function just returns the reversed string of the argument string.
    strcmp() compares two string arguments and returns zero if they r zero.

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by abhishek.in
    its very easy to check for palindromes.
    just a few lines of code in c/c++

    I hope you get a good grade on their homework assignment you just did for them.

    That's a very common assignment given to students.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New Coder
    Join Date
    Nov 2004
    Location
    Kansas
    Posts
    86
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It is? Hm... in my C++ class I never was given an assignment as simple as this...

  • #6
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    dun worry spookster......i do not intend to copy. it's just that i wanna know the flow. so u can rest assure that i wont get such good marks. and by the way, the code doesn't work. so i guess...dream come true huh?
    Warm Regards,
    Mivec

  • #7
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by Ryltar
    It is? Hm... in my C++ class I never was given an assignment as simple as this...
    I had to write a palindrome program in assembly when I was in college. It's simple enough to introduce students to a language.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #8
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    abhishek.in,
    hey...thanks for showing me the flow of the programme.however, in my last post i did mention that ur programme computes errors. anyhow, i have constructed my version. here it is:

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #define size 100
    
    int isPalindrome (char strhld[]);
    
    void main()
    {
    
    	char strsrc[size];
    	char strhld[size];
    	int answer;
    
    	printf("\n Enter String:= "); 
    	strcpy(strhld, gets(strsrc)); // gets() to get the string inputed 
    	answer = isPalindrome(strhld);
    	
    	if (answer == 1)
    		printf("\n Entered string \"%s\" is a palindrome\n",strhld);
    	else if (answer == 0)
    		printf("\n Entered string \"%s\" is not a palindrome\n",strhld);
    	else
    		printf("\n Entered string \"%s\" is not in this question\n",strhld);
    } 
    
    int isPalindrome (char strhld[])
    {
    	char strtmp[size];
    
    	strcpy(strtmp,strhld);
    	strrev(strtmp);//strrev() function just returns the reversed string of the argument string. 
    
    	if(strcmp(strhld,strtmp)==0)//strcmp() compares two string arguments and returns zero if they r zero.
    		return 1;        
    	else
    		return 0;
    		
    }
    thanks again...
    Warm Regards,
    Mivec

  • #9
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Sure looks like you copied all the important sections. I hope he..errr you get a good grade.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #10
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yo spooks...i dunno whats ur grudge against me but u're the boss here....so...i'll just be silent for this time. it's as if u din have ur 1st time in programming....
    Warm Regards,
    Mivec

  • #11
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and spooks....u're the genius around here and u should know that reserved words CANNOT be changed...so if u say that is copying...i hv no words to say anymore...
    Warm Regards,
    Mivec

  • #12
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    I just don't like cheaters. People don't learn what the instructor intended them to learn. Although that does provide me with better job security because those people that copy other peoples programs and turn them in as their own are the people that finish college and still don't know how to program so that creates less competition for me in the job market.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #13
    New Coder
    Join Date
    Jan 2005
    Location
    INDIA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    stop fighting!!

    hey , stop fighting guys.
    i dont say that copying code is alright, but if u need an implementation for understanding the logic, then whats wrong.
    n by the way, mivek has successfully removed some errors from the prog. so why dont we credit him for that.
    i think we shouldnt discourage someone for asking a problem, however simple it might be.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •