/*To check whether a string is palindrome*/
If you mean not using pointers, then:
int palindrome (const char s[])
{
size_t len, i, j;
len = strlen (s);
for (i=0, j=len-1, check=1; check==1 && i if (s[i] != s[j]) check= 0; } return check; } but if it's using pointers, then: int palindrome (const char *s) { size_t len; const char *p, *q; len = strlen (s); for (p=s, q=s+len-1, check=1; check==1 && p if (*p != *q) check= 0; } return check; }
int palindrome(char * string)
{
int result = 0;
int count = 0;
char * a = string;
char * b = string+strlen(string);
while((*a++ strlen(string))
result = 1;
return result;
}
#include
#include
#include
void main()
{
clrscr();
int i,j=0;
char s[40]=" ";
int p = 1;
printf("/nEnter the string;");
gets(s);
for(i=strlen(s)-1;i>=0;i--,j++)
{
if (s[j] !=s[i])
{
p=0;
break;
}
}
if(p)
printf("Given string %s is palindrome",s);
else
printf("Given string %s is not palindrome",s);
getch();
}
strlen is one of the string functions
#include<stdio.h>
#include<ctype.h>
#include<string.h>
/* returns true of the given string represents a palindrome,
otherwise returns false */
bool is_palindrome (const char* str) {
size_t len;
char *left, *right;
if (!str) return false; /* null-strings are not palindromes */
len = strlen (str);
if (!len) return false; /* empty strings are not palindromes */
left = (char*) str;
right = (char*) str + len - 1;
while (left<right && *left==*right) {
++left;
--right;
}
return (*left==*right);
}
int main (void) {
char str[BUFSIZ], cpy[BUFSIZ];
size_t i, index;
printf("Enter a string: ");
gets(str);
/* strip punctuation and convert to lower case */
i=0;
for (index=0;index<BUFSIZ;++index) {
cpy[i]=tolower(str[index]);
if (cpy[i]>='a' && cpy[i]<='z')
++i;
}
cpy[i]='\0';
/* print result */
printf ("The string "%s" is ", str);
if (!is_palindrome (cpy))
printf ("not ");
printf ("a palindrome.\n");
}
Example usage:
Enter a string: Madam, I'm Adam
The string "Madam, I'm Adam" is a palindrome.
Enter a string: Madam, I'm not Adam
The string "Madam, I'm not Adam" is not a palindrome.
/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }
import java.util.Scanner; public class Palindrome{ public static void main(String[] args){ String front; String back =""; char[] failure; String backwards; Scanner input=new Scanner(System.in); System.out.print("Enter a word: "); front=input.next(); front=front.replaceAll(" ", ""); failure=front.toCharArray(); for (int i=0; i<failure.length; i++){ back=failure[i] + back; } if (front.equals(back)){ System.out.print("That word is a palindrome"); }else System.out.print("That word is not a palindrome"); }}
use the strrev() function on the given string and compare with original string.If both are equal they are palindromes else not.
Private Sub Command1_Click() a = Text1.Text b = StrReverse(a) If a = b Then Print "palindrome" Else Print "not palindrome" End If End Sub
This program only suits PHP. If you want a proper one try C program for it available on web <body> <?php if(isset($_POST['submit'])) { $text = $_POST['text']; $string = mysql_real_escape_string($text); $invert = strrev($string); if($string == $invert) { echo "<br>Given number is a palindrome!!"; } else { echo "<br>Given number is not a palindrome!!"; } } ?> <form method="post"> <input type="text" name="text" id="text" /> <input type="submit" name="submit" value="Submit" id="submit" onclick="<?php $_SERVER['PHP_SELF']; ?>" /> </form> </body>
Reverse the string and compare it to the original. If they match, then it is a palindrome.
/*To check whether a string is palindrome*/includeincludevoid main () { int i,j,f=0; char a[10]; clrscr (); gets(a); for (i=0;a[i]!='\0';i++) { } i--; for (j=0;a[j]!='\0';j++,i--) { if (a[i]!=a[j]) f=1; } if (f==0) printf("string is palindrome"); else printf("string is not palindrome"); getch (); }
int Palindrome(char *userStringStart) { char *userStringEnd = userStringStart; do { *userStringEnd |= 32; } while(*++userStringEnd); do{ while(*userStringStart < 97 *userStringStart > 122) userStringStart++; while(*userStringEnd < 97 *userStringEnd > 122) userStringEnd--; if(*userStringStart != *userStringEnd) return 0; } while(userStringStart++ <= userStringEnd--); return 1; }
import java.util.Scanner; public class Palindrome{ public static void main(String[] args){ String front; String back =""; char[] failure; String backwards; Scanner input=new Scanner(System.in); System.out.print("Enter a word: "); front=input.next(); front=front.replaceAll(" ", ""); failure=front.toCharArray(); for (int i=0; i<failure.length; i++){ back=failure[i] + back; } if (front.equals(back)){ System.out.print("That word is a palindrome"); }else System.out.print("That word is not a palindrome"); }}
#include <stdio.h> #include <conio.h> #include <string.h> void input(char a[ ]) { int i; printf("\n enter string\n"); scanf("%s",a); } void output(char a[ ]) { printf("\n string is %s",a); } int palindrome(char a[ ]) { int n,i; n=count(a); n=n-1; i=0; for(;a[n]==a[i] && n>=i;i++,n--); if(n>=i) return 0; else return 1; } void main( ) { char a[80],b[80],s; int n; printf("\n check palindrome"); input(a); n=palindrome(a); output(a); if(n==1) printf("\n palindrome"); else printf("\n not palindrome"); getch(); }
#include <stdio.h> #include <conio.h> #include <string.h> void input(char a[ ]) { int i; printf("\n enter string\n"); scanf("%s",a); } void output(char a[ ]) { printf("\n string is %s",a); } int palindrome(char a[ ]) { int n,i; n=count(a); n=n-1; i=0; for(;a[n]==a[i] && n>=i;i++,n--); if(n>=i) return 0; else return 1; } void main( ) { char a[80],b[80],s; int n; printf("\n check palindrome"); input(a); n=palindrome(a); output(a); if(n==1) printf("\n palindrome"); else printf("\n not palindrome"); getch(); }
#include <stdio.h> #include <conio.h> #include <string.h> void input(char a[ ]) { int i; printf("\n enter string\n"); scanf("%s",a); } void output(char a[ ]) { printf("\n string is %s",a); } int palindrome(char a[ ]) { int n,i; n=count(a); n=n-1; i=0; for(;a[n]==a[i] && n>=i;i++,n--); if(n>=i) return 0; else return 1; } void main( ) { char a[80],b[80],s; int n; printf("\n check palindrome"); input(a); n=palindrome(a); output(a); if(n==1) printf("\n palindrome"); else printf("\n not palindrome"); getch(); }
use the strrev() function on the given string and compare with original string.If both are equal they are palindromes else not.
plz any1 give code on given exampleAs i know we can check String is it palindrome or not..take a look onCode_for_palindrome_checking_in_c_programmingorvoid main(){char strsrc[100];char strtmp[100];printf(" Enter String:= ");gets(strsrc);strcpy(strtmp,strsrc);strrev(strtmp);if(strcmp(strsrc,strtmp)==0)printf("\n Entered string " %s " is palindrome",strsrc);elseprintf("\n Entered string "%s" is not palindrome",strsrc);getch();}You cite 2 examples of what you are looking for so why are you asking the question? The palindrome is word "radar" so obviously the program needs to extract individual word from the string in order to test. That is a simple thing to do. I am not going to do it for you because if I do you do not learn what you need to know.....i did separated string by for (i=0 arr!=arr.lnegth i++){if(arr[i]==" ")} then each string checked for this code but that not right as persistence employee said..
Private Sub Command1_Click() a = Text1.Text b = StrReverse(a) If a = b Then Print "palindrome" Else Print "not palindrome" End If End Sub
This program only suits PHP. If you want a proper one try C program for it available on web <body> <?php if(isset($_POST['submit'])) { $text = $_POST['text']; $string = mysql_real_escape_string($text); $invert = strrev($string); if($string == $invert) { echo "<br>Given number is a palindrome!!"; } else { echo "<br>Given number is not a palindrome!!"; } } ?> <form method="post"> <input type="text" name="text" id="text" /> <input type="submit" name="submit" value="Submit" id="submit" onclick="<?php $_SERVER['PHP_SELF']; ?>" /> </form> </body>
#include <stdio.h> #include <conio.h> void main() { int num,rev=0,m,r; clrscr(); printf("enter any number"); scanf("%d",&num); m=num; while(num>0) { r=num%10; rev=rev*10+r; num=num/10; } if(rev==m) printf("given number is palindrome"); else printf("given number is not palindrome"); getch(); } this is the answer.