This blog consists of C and C++ programs. C and C++ programming is the basics to learn any programming language. Most of the programs are provided with their respective outputs. This blog also contains Data Structures programs using Object-Oriented Programming (C++). Some of the best books for learning C and C++ programming are also mentioned.

Showing posts with label Palindrome. Show all posts
Showing posts with label Palindrome. Show all posts

Monday, 19 August 2013

C++ program to check whether the given string is Palindrome or not (3)

Palindrome:
Palindromes are words or phrases that read the same in both directions.
Some examples of common palindromic words: civic, dewed, deified, dad, mom, devoved, hannah, repaper, radar, level, rotor, kayak, reviver, racecar, redder, madam, redder, bob, pop, tot, malayalam, noon, rotator, rotavator, stats, solos, tenet and refer.

Program:
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[50],m[50];
int p=1,i;
clrscr();
cout<<"Enter the string: ";
cin>>s;
strcpy(m,s);
strrev(m);
for(i=0;i<=strlen(s)-1;i++)
{
if(*(m+i)!=*(s+i))
{
p=0;
break;
}
}
if(!p)
cout<<"\n"<<s<<" is not a Palindrome";
else
cout<<"\n"<<s<<" is a Palindrome";
getch();
}



Thursday, 8 August 2013

Program to check whether the given number is Palindrome or not


#include<stdio.h>
void main()
{
int n, rev=0, rem,temp;
clrscr();
printf("Enter any number: ");
scanf("%d", &n);
temp=n;
while(temp!=0)
{
rem=temp%10;
rev=rev*10+rem;
temp=temp/10;
}
if(rev==n)
printf("%d is a Palindrome",n);
else
printf("%d is not a Palindrome",n);
getch();
}





Thursday, 27 June 2013

Program to check whether the given string is Palindrome or not (2)

#include <stdio.h>
#include <string.h>
int main()
{
char a[100], b[100];
clrscr();
printf("Enter the string: ");
gets(a);
strcpy(b,a);
strrev(b);
if(strcmp(a,b) == 0)
printf("\nThe string is a Palindrome");
else
printf("\nThe string is not a Palindrome");
getch();
}


Program to check whether the given string is Palindrome or not (1)

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str1[50],rstr[50],ch;
int i=0,k=0;
cout<<"Enter the string:";
cin>>str1;
strcpy(rstr,str1);
k=strlen(str1);
for(i=0;i<k/2;i++)
{
ch=rstr[i];
rstr[i]=rstr[k-i-1];
rstr[k-i-1]=ch;
}
if(strcmp(str1,rstr))
cout<<"\n"<<str1<<" is not a palindrome";
else
cout<<"\n"<<str1<<" is a palindrome";
getch();
}