Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Reversing an integer number: Write a C/C++ function that accepts an integer numb

ID: 3641362 • Letter: R

Question

Reversing an integer number:
Write a C/C++ function that accepts an integer number as parameter and returns a number of which the order of its digits have been reversed.
To test your function use the main() function given bellow. Your job is to define the function reverseNumber() and run (execute) the program to check that it works correctly.
The reverseNumber() function should NOT print anything to the output. It should return the reversed number to main() function and main will print it out.

Do not modify the part of the program given to you. Just copy it and paste it in your solution.

/* This program reads an integer number from the input and prints our the reverse
number. */
#include <iostream>
using namespace std;
//Function declaration
int reverseNumber(int num);
int main()
{
int num, reversedNum;
cout << " Please enter a number: ";
cin >> num;
reversedNum = reverseNumber(num);
cout << "The reverse number is: " << reversedNum << endl;
system("pause");
return 0;
}
//Function definition.
(Add your code here)

Sample input/output:
First execution:
Please enter a number: 3489
The reverse number is: 9843
Press any key to continue . . .

Second execution:
Please enter a number: -213439
The reverse number is: -934312
Press any key to continue . . .

Third execution:
Please enter a number: 5
The reverse number is: 5
Press any key to continue . . .

Explanation / Answer

Please rate...

#include <iostream>
#include<stdlib.h>
using namespace std;
//Function declaration
int reverseNumber(int num);
int main()
{
int num, reversedNum;
cout << " Please enter a number: ";
cin >> num;
reversedNum = reverseNumber(num);
cout << "The reverse number is: " << reversedNum << endl;
system("pause");
return 0;
}
//Function definition.
int reverseNumber(int n)
{
    int a,s=0;
    while(n!=0)
    {
        a=n%10;
        s=(s*10)+a;
        n=n/10;
    }
    return s;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote