Example:- Write a C++ program to enter any number and check whether the number is palindrome or not using while loop.*.
To check whether the number is palindrome or not using while loop.*/
//Now select File-> New in Notepad and type the C++ program
#include<iostream>
using namespace std; intmain( )
{
int n, num, digit, rev = 0;
cout <<"Enter a positive number:”;
cin>>num;
n = num;
while(num)
{ digit=num% 10;
rev= (rev* 10) +digit;
num = num/10;
cout<<“The reverse of the number is:"<<re
<<end1;
if (n ==rev)
cout<<"The number is a palindrome”;
else
cout<< “The number is a palindrome”;
return 0;
}
//save this file as pali_cpp.cpp
#Now select File → New in Notepad and type the Python program
#Save the File as pali.py.Program that complies and executes a .cpp file
import sys, os, getopt
def main(argv);
cpp_file= ”
exe_file= ”
opts.args = getopt.getopt(argv, “i:” ,[‘ifile-])
for o, a in opts:
if o in (“-i” , “—file”):
cpp_file =a+ ‘.cpp’
exe_file =a+ ‘.exe’
run(cpp_file, exe_file)
def run(cpp_file, exe_file):
print(“Compiling” + eppfile)
os.system(‘g++’ + cpp_file +’ -o’ + exe file)
print(“Running” + exe_file)
print(“...........“)
print
os.system(exefile)
print
if_name_== ’_main_’:
#program starts executing from here
main(sys.argv[1:])
Output of the above program
C:\Program Files\OpenOffice 4\program>Python
c:\pyprg\pali.py -i c:\pyprg\pali_cpp
Compiling c:\pyprg\pali_cpp.cpp
Running c:\pyprg\pali_cpp.exe
Enter a positive number: 56765
The reverse of the number is: 56765
The number is a palindrome
C:\Program Files\OpenOffice 4\program>Python
c:\pyprg\pali.py -i c:\pyprg\pali_cpp Compiling
c:\pyprg\pali_cpp.cpp Running c:\pyprg\pali_cpp.exe
Enter a positive number: 56756
The reverse of the number is: 65765
The number is not a palindrome
.......................