...

View Full Version : palindrome programme



mivec
01-28-2005, 10:38 AM
hi all,
does anyone have a sample of a palindrome programme? or can someone advice me on how to write one?...thanks a million...

Sayonara
01-28-2005, 10:53 AM
Are you trying to confirm or generate palindromes?

abhishek.in
01-28-2005, 01:12 PM
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.

Spookster
01-28-2005, 02:00 PM
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.

Ryltar
01-28-2005, 11:12 PM
It is? Hm... in my C++ class I never was given an assignment as simple as this...

mivec
01-29-2005, 07:01 AM
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?

Spookster
01-29-2005, 07:30 AM
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.

mivec
01-30-2005, 04:41 AM
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:



#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...

Spookster
01-30-2005, 06:00 PM
:rolleyes: Sure looks like you copied all the important sections. I hope he..errr you get a good grade.

mivec
01-30-2005, 06:30 PM
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.... :rolleyes:

mivec
01-30-2005, 06:38 PM
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... :eek:

Spookster
01-31-2005, 12:00 AM
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. :)

abhishek.in
01-31-2005, 03:41 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum