In this, we are going to see Functions, the program is based on function which Calculates, Profit or Loss.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
// creating a function for palindrome
int palindrome()
{
int num; // number to be taken
int n2 = 0; // reverse number being generated
int rem; // remainder
int qu; // quotient
cout << "Enter number to check if its Palindrome or not :\n";
cin >> num;
int n = num;
// value of num, initiaized in n to perform operations on n
while (n > 0)
{
rem = n % 10; // found remainder
n2 = n2 * 10 + rem; // gemerating number in reverse
qu = n / 10;
n = qu;
}
if (n2 == num)
{
cout << num << " is a Palindrome number !";
}
else
{
cout << num << " is NOT a Palindrome number !";
}
return num;
}
void main()
{
clrscr();
palindrome();
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int palindrome()
{
int num; // number to be taken
int n2 = 0; // reverse number being generated
int rem; // remainder
int qu; // quotient
cout << "Enter number to check if its Palindrome or not :\n";
cin >> num;
int n = num;
// value of num, initiaized in n to perform operations on n
while (n > 0)
{
rem = n % 10; // found remainder
n2 = n2 * 10 + rem; // gemerating number in reverse
qu = n / 10;
n = qu;
}
if (n2 == num)
{
cout << num << " is a Palindrome number !";
}
else
{
cout << num << " is NOT a Palindrome number !";
}
return num;
}
int main()
{
palindrome();
return 0;
}
#ENJOY CODING
Â
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP