Read a string and check whether it is palindrome or not.
//Read a string and print the string is palindrome or NOT palindrome.
#include<stdio.h>
void main()
{
char a[500],b[500];
clrscr();
printf("\n Enter A String :- ");
scanf("%s",&a);
strcpy(b,a); //copies string a to b
strrev(b); //reverses string b
if(strcmp(a,b)==0) //compares if the original and reverse strings are same
printf("\n %s is a palindrome",a);
else
printf("\n %s is not a palindrome",a);
getch();
}
//Read a string and print the string is palindrome or NOT palindrome without using inbuilt functions.
#include<stdio.h>
void main()
{
char a[500];
int i,b;
clrscr();
printf("\n Enter A String :- ");
scanf("%s",&a);
b = strlen(a);
for(i=0;i<=((b-1)/2);i++)
{
if(a[i] != a[b-1-i])
printf("\n %s is not palindrome",a);
}
printf("\n %s is palindrome",a);
getch();
}
#include<stdio.h>
void main()
{
char a[500],b[500];
clrscr();
printf("\n Enter A String :- ");
scanf("%s",&a);
strcpy(b,a); //copies string a to b
strrev(b); //reverses string b
if(strcmp(a,b)==0) //compares if the original and reverse strings are same
printf("\n %s is a palindrome",a);
else
printf("\n %s is not a palindrome",a);
getch();
}
//Read a string and print the string is palindrome or NOT palindrome without using inbuilt functions.
#include<stdio.h>
void main()
{
char a[500];
int i,b;
clrscr();
printf("\n Enter A String :- ");
scanf("%s",&a);
b = strlen(a);
for(i=0;i<=((b-1)/2);i++)
{
if(a[i] != a[b-1-i])
printf("\n %s is not palindrome",a);
}
printf("\n %s is palindrome",a);
getch();
}
Comments
Post a Comment