Skip to main content

C++ Program to test whether a number is palindrome or not.

A number is called palindrome, if it reads the same on reading from both left and right. Thus, 121 is a palindrome, but 123 is not. Because, on reading from the right, it is 321 and not 123.



The steps followed are,

  • get the number to be checked.
  • reverse the number.
  • compare with the given number.
  • conclude.
The program would be as follows.

The Program


/palindrome 25/08/2013
#include<conio.h>
#include<iostream.h>

class dom
{
int dgt,dum;
int flag;
public:
void get()
{
clrscr();
cout<<"enter the digit:";
cin>>dgt;
dum=dgt;
flag=0;
}
void check();
void disp()
{
if (flag==1) cout<<endl<<"palindrome";
else cout<<endl<<"not palindrome";
}
};
void dom::check()
{
flag=0;
int sum=0,w;
while (dum!=0)
{
w=dum%10;
sum=sum*10+w;
dum=dum/10;
}
cout<<"reversed:"<<sum;
if (sum==dgt)
flag=1;
};

void main()
{
clrscr();
dom obj;
obj.get();
obj.check();
obj.disp();
//***vaju**
getch();
}

Comments

Popular posts from this blog

Talky Messenger Documentation & Setup

( Github ) Just created a chat app that runs in Node and Socket. the attempt was worthy. Talky is a messenger app built with Node, Express, Socket, Angular & Bootstrap. It's like a server-client structure. (But obviously not like the one we done at OS lab using shared memory). It has a broadcasting structure. Talky does not keep a log on chat. i.e., It doesn't have a memory or database. When we close the browser window, chat history is lost. There I also added a basic console, protected by a password, to send real-time notifications to active clients. The name 'Talky' was suggested by a friend of mine. (hey, thank you for that. The fact is that I am not really good at naming...😝) What if sometimes your college blocks WhatsApp? Try Talky. ( There is also a website on internet in the name of 'Talky' which has no connection with this one. ) Download Talky Messenger To use Talky, all you need is 3 things: Node server Source code...

One cannot judge the backend complexity by looking at the frontend.

I've seen people saying "this one is pretty easy to implement" by looking at the frontends of some awesome applications. Making frontend and user interface clean and KISS (keep it simple and stupid) is essential for an application to win the users. By that it never meant that it was easy. To make an app more user-friendly, developers has to write extra code to balance the "things" that they have abstracted. For an instance, consider www.google.com page. How simple and stupid that page is... 6 large letters and a text box. What else in it?! By that would you conclude Google is easy? I do also have personal experience from a guy, who comments after evaluating our project of 5000 LOC that "is it only this much to do that? Child's play". He also suggested a new feature to add, which was a nice one. On the implementation phase of that feature, we pulled him to find a bug. And after spending 30 mins on our code his reaction - "Someone's ca...