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

Wednesday, April 16, 2014

C Program to check the number is palindrome or not

C Program to check the number is palindrome or not
 #include<stdio.h>
#include<conio.h>
void main()
{
int i,temp,sum=0,remainder,number;
clrscr();
printf("Enter the number to check Palindrome: ");
scanf("%d",&number);
temp=number;
while(number>0)
{
remainder=number%10;
number=number/10;
sum=sum*10+remainder;
}
printf("\nreverse of given number is= %d\n",sum);
if(sum==temp)
printf("number is palindrome");
else
printf("number is not palindrome");
getch();
}

Monday, April 7, 2014

C Program to create a menu based program using switch case

C Program to create a menu based program using switch case

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int s,n1,rem,rev=0,num,n,f=1,i,sum=0;
clrscr();
printf("Choose the option\n");
printf("1. Cheque wheather number is palindrome\t2. Factorial value\n");
printf("3. Sum of n natural number\t\t4. Exit\n");
scanf("%d",&s);
switch(s)
{
case 1:
printf("Enter the number\n");
scanf("%d",&n1);
num=n1;
while (n1>0)
{
rem=n1%10;
n1=n1/10;
rev=rev*10+rem;
}
printf("reverse number is %d\n",rev);
if(num==rev)
printf("Number is palindrome");
else
printf("Number is not palindrome\n");
break;
case 2:
printf("Enter the number\n");
scanf("%d",&n);
for(i=n;i>0;i--)
f=f*i;
printf("factorial is %d",f);
break;
case 3:
printf("How many numbers do you want to enter\n");
scanf("%d",&n);
printf("Enter %d numbers\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&n1);
sum=sum+n1;
}
printf("sum of %d numbers is %d",n,sum);
break;
case 4:
exit();
}
getch(0);
}

Thursday, April 3, 2014

C++ Program to check whether the number is palindrome or not

C++ Program to check whether the number is palindrome or not
A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction.[1] Famous examples include "Amore, Roma", "A man, a plan, a canal: Panama" and "No 'x' in 'Nixon'". --- wiki

#include<iostream.h>
#include<conio.h>
class palindrome
{
int n1,n2,rem,rev;
public:
void input()
{
cout<<"Enter the number\n";
cin>>n1;
}
void calculation()
{
rev=0;
n2=n1;
while (n1>0)
{
rem=n1%10;
n1=n1/10;
rev=rev*10+rem;
}
}
void output()
{
if(n2==rev)
cout<<"Number is palindrome";
else
cout<<"Number is not palindrome";
}
};
void main()
{
clrscr();
palindrome a;
a.input();
a.calculation();
a.output();
getch();
}