Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
2.4k views
in Importing C++ Programs in Python by (49.1k points)
closed by

Write a C++ program to check whether the given number is palindrome or not. Write a program to execute it?

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

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

.......................

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...