Hi! kindly help me solve my assignment? It is all about making a palindrome program in C..tnx! Use .c in saving your work..because some people save it on a .cpp and we are required in a .c extension! tnx again!
How do I program a palindrome in C?
#include%26lt;stdio.h%26gt;
#include%26lt;string.h%26gt;
#define size 26
void main()
{
char strsrc[size];
char strtmp[size];
clrscr();
printf("\n Enter String:= "); gets(strsrc);
strcpy(strtmp,strsrc);
strrev(strtmp);
if(strcmp(strsrc,strtmp)==0)
printf("\n Entered string \"%s\" ispalindrome",strsrc);
else
printf("\n Entered string \"%s\" is not
palindrome",strsrc);
getch();
}
it was using string .h header file
#include %26lt;stdio.h%26gt;
#include %26lt;string.h%26gt;
#define size 26
#define TRUE 1
#define FALSE 0
main () {
char string[size];
int ispalindrome = TRUE;
int i,j;
printf("Enter a string no more than 26 characters ");
gets(string);
j = strlen(string) - 1;
i = 0;
while((i %26lt;= j) %26amp;%26amp; (ispalindrome==TRUE)) {
if(string[i] != string[j]) {
ispalindrome = FALSE;
}
i++;
j--;
}
if(ispalindrome==TRUE) {
printf("%s is a palindrome!\n", string);
}
else {
printf("sorry, %s is not a palindrome\n", string);
}
}
// without using string.h
business cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment