Inversion of numbers

Pages: 12
i know it's resolved with string and easy but i want without string
Last edited on
sorry
i'm tired
tnks for your Guidance
good bye
You can do this by using modulo division to seperate the individual digits and then recombine them with multiplication. Give it a shot...

EDIT: Hmmm, this method may only work on integers and I see you want to work with floats. Might take a bit more thought...
Last edited on
wihtout string,class,...

Doesn't answer my question. What sort of string? Are you not even allowed to use C-style strings?
i know it's resolved with string and easy but i want without string


Why would you intentionally want to make the problem harder than it is?
closed account (Dy7SLyTq)
1) for the lulz
2) your a professor trying to get your students to be creative

thats all i got
since you can't use strings -or rather not allowed to-, i bet you're solving a homework.
anyway, this is the code for integers, you should convert it to work with floats yourself:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//	pre-condition: digits is large enough to hold each digit in a cell.
//	post-condition: each cell of digits contains the corresponding digit of target.
void splitIntoDigits(int target , int digits[])
{
	int oneDigit = target;
	int degree = 0;
	int maxDegree;

	for( maxDegree = 0; oneDigit ; oneDigit/=10 , maxDegree++) ; //find how many digits is in the number.

	for(int i=0 ; i<maxDegree ; i++)	//begin splittin the target.
	{
		oneDigit = target;	// make temp the current value of target.
		for(degree = 0 ; oneDigit >= 10 ; oneDigit/=10 , degree++);	// determine the last digit and its degree.
		digits[i] = oneDigit;	// assign the digit to the corresponding cell.
		target -= (digits[i]* std::pow(10.0,degree));	// delete the last digit from target.
	}
}
use this function for integer:

void reverseInt(int myInt) {
if(myInt/10!=0 ) {
reverseNum = reverseNum *10 +(myInt%10);
reverseInt(myInt/10);
}
else {
reverseNum = reverseNum *10 +(myInt%10);
}
}

reverseNum is declared globally and initialized to 0;

could not think of yet how to convert the float or double to Int.
if you can convert say 556.66f to 55666 as integer then that solves the problem.

Disch

DTSCode
i just want with hard way make myself stronger

Rechard3
This is not a homework

you see that the question solution is hard.

jrfrago
Anyway, thanks.

Last edited on
@MPERSIA:
you see that the question solution is hard.


no, YOU are making it hard by not using the true power of the language.
Manipulating the float data and keeping it unchanged is almost impossible especially for float of more decimals. Even using the stringstream doesn't help to keep the float from being changed. To keep the data unchanged, use string.
Last edited on
Topic archived. No new replies allowed.
Pages: 12