A simple C++ program using class
Note: Use new compiler (Code blocks or Dev C++) to run these C++ programs. Old Turbo C compiler does not supports some new features of C++.
If you want to run these programs on old Turbo C++ compiler use <iostream.h> instead of <iostream> , do not use ( using namespace std; ) , use { getch(); } to hold run-time screen , use void main() instead of int main() .
If you want to run these programs on old Turbo C++ compiler use <iostream.h> instead of <iostream> , do not use ( using namespace std; ) , use { getch(); } to hold run-time screen , use void main() instead of int main() .
C++ program to check a number weather palindrome or not.
#include<iostream>
using namespace std;
class palindrome
{
private:
int num;
public:
void get(int u)
{
num = u;
}
void disp()
{
int temp, rem, rev;
temp = num;
while(num>0)
{
rem = num % 10;
rev = rev*10 + num;
num = num / 10;
}
if (rev == temp)
cout << " Entered number is palindrome. \n";
else
cout << "Entered number is not palindrome. \n";
}
};
int main()
{
int a;
palindrome x;
cout << "Enter a number. \n";
cin >> a;
x.get(a);
x.disp();
return 0;
}
Comments
Post a Comment