answersLogoWhite

0


Best Answer

// reversed.cpp

#include

using std::cout;

using std::cin;

using std::endl;

using std::ios;

#include

using namespace std;

int reversByValue(int);

int main()

{

int num;

cout << "Enter a number (0 for End): "

cin >> num;

while (num != 0) {

cout << "The number with its digits reversed is: "

<< reversByValue(num) << endl;

cout << "\nEnter a number (0 for End): ";

cin >> num;

}

cin.ignore();

return 0;

}

int reversByValue(int numRev)

{

int resultNum = 0;

while (numRev != 0)

{

resultNum = (resultNum * 10) + (numRev - (numRev / 10) * 10);

numRev = numRev / 10;

}

return resultNum;

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a function that takes an integer value and returns the number with its digits reversed?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a function that reads an integer and determines and prints how many digits in the integer are 7s?

== == // Returns number of 7s in num. int numSevens(int num) { int _num = num; int numSevens = 0; while( _num &gt; 0 ) { if( (_num % 10) == 7 ) { ++numSevens; } _num /= 10; } return numSevens; }


How do you write a visual basic program to sum the odd number digits of a 12 digit code using division and Mod and while loops?

Function sum_odd_digits(ByVal number As Integer) As Integer Dim digit As Integer sum_odd_digits = 0 While number &lt;&gt; 0 digit = number Mod 10 If digit And 1 Then sum_odd_digits = sum_odd_digits + digit number = number / 10 End While End Function


How do you find out how many digits are in integer using vbscript?

num=32767 MsgBox(len(num))


WAP that initialize an integer and display whether it is single digit two digit three digit or more than three digits?

Please note that the answer below is the most expandable answer. By this I mean that it can be easily changed to display the output given for any number of digits in a number. There are far simpler solutions which do not require any explanation, but are useless in an evolving setting. To answer this question, we need to look at the Math.log10 function. Ignoring the possible anomalous results of this function (check the current Java API to find out what other results are possible), we can find the number of digits in a number by using: (log10(n) + 1). If n is equal to the value 10^m for a value m, then the function will return m. That is to say, if n is equal to 10, then the result of the function will be 1, since 10^1 = 10. Likewise, if n is equal to 100, then the result of the function will be 2, since 10^2 = 100, and so forth. If you look at the numbers in between, you will find the function returns a decimal result. log10(99) = 1.9956, for example. This means that the range of answers you will get for the values [10,99] will return the range of answers from [1.0,2.0). The same can be found looking at the range of values [100,999] which return in the range [2.0,3.0). From this we find that the function log10 always returns either an integer or a fractional value which will always be at most 1.0 less than the number of digits in the number sent to it. In either case, if we simply truncate it (cast the double as an int) and add 1, we come up with our getNumDigits function. int getNumDigits(int n) { return ((int) Math.log10(n)) + 1; } And to finish up your question, we can add in another method to deal with the results. // we're assuming the number n comes from somewhere else, // whether hard-coded or passed as input to the program void displayNumDigits(int n) { switch(getNumDigits(n)) { case 1: System.out.println("One digit"); break; case 2: System.out.println("Two digits"); break; case 3: System.out.println("Three digits"); break; default: System.out.println("More than three digits"); } }


How do you show a positive integer for example 12345678901234567890 in C sharp that has more than 17 digits?

There is Int64 class, it will do it.

Related questions

Write a function that reads an integer and determines and prints how many digits in the integer are 7s?

== == // Returns number of 7s in num. int numSevens(int num) { int _num = num; int numSevens = 0; while( _num &gt; 0 ) { if( (_num % 10) == 7 ) { ++numSevens; } _num /= 10; } return numSevens; }


I am 13 My coach is 31 which is my age with the digits reversed What is the fewest number of years in which the digits of our ages will be reversed again?

after 11yrs.


You are 13My coach is 31 which is your age with the digits reversed What is the fewest number of years in which the digits of your ages will be reversed again?

11yrs.


Is 1212121212.... an integer?

If it ever ends, then it is.If there are no digits after the decimal point, it's an integer.


What is the largest number of eight digits with one of its digits 0 and remains the same when its digits are reversed?

An eight digit number with one zero cannot remain the same when its digits are reversed. It must have an even number of 0s.


How many 2 digits numbers are such that the difference of the number and the number with the digits reversed is a perfect square?

If the number with the digits reversed can have a leading 0 so that it is a 1-digit number, then 16. Otherwise 13.


Is 3.5 a odd integer?

It is not an integer, since it has digits after the decimal point.


What is 9 times 8 with the digits reversed?

27


What is the four digit number whose digits are reversed when multiplied by nine?

Find a four digit number whose digits will be reversed when multiplied by nine?


What five digits number when you multiply by four is the same the number when you reversed it?

five digits number when you multiply by four is the same the number when you reversed it is 21978*4 = 87912


How do you use Microsoft Excel roundup?

RoundUp function returns a number rounded up to a specified number of digits. (Rounds away from 0.)Syntax: RoundUp( number, digits )number = number to round updigits = number of digits to round the number up to


Is 3.14 an integer?

Any number that has non-zero digits after the decimal point is NOT an integer.