Need help in C

TecHNooB

Diamond Member
Sep 10, 2005
7,458
1
76
I'm trying to write a function where the user inputs a long integer with an even amount of digits. The digits are read off the end two at a time using mod. How can I write a function using recursion that will print the numbers in order? Since I'm using mod to read the last two numbers off the end, the order of the numbers will be backwards.

Also, how come the division function acts screwy when dividing a long long int number? For example, 1234 / 10 isn't giving me 123.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Why not use a string?

Are you saying that give 234567 you want to write out 67 45 23 instead of a full reversal to 765432 ?

> Also, how come the division function acts screwy when dividing a long long int number? For example, 1234 / 10 isn't giving me 123.

Either a code error or you're probably missing a type cast or getting an implied type cast that you don't realize.

For example, given
double x = 1.0 + (2/3) ;
the result will usually be 1.0 + 0 = 1.0 since the integer division takes place before the result gets promoted to a double.
double x = 1.0 + (2/ (double) 3) ;
would give you the result you'd expect.
 

blackllotus

Golden Member
May 30, 2005
1,875
0
0
Originally posted by: DaveSimmons
For example, given
double x = 1.0 + (2/3) ;
the result will usually be 1.0 + 0 = 1.0 since the integer division takes place before the result gets promoted to a double.
double x = 1.0 + (2/ (double) 3) ;
would give you the result you'd expect.

I believe you can also just do
double x = 1.0 + (2.0/3);
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: blackllotus
I believe you can also just do
double x = 1.0 + (2.0/3);
Sure, but not if the code is actually
int a, b ;
double x, y ;

x = y + ( a / b ) ; // (a/b) will be integer division, (2/3) = 0

then you need to cast one int to a double to get the result that you usually want.
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
Is there any particular reason you are reading the digits off two at a time or for only an even amount of digits?
 

TecHNooB

Diamond Member
Sep 10, 2005
7,458
1
76
Originally posted by: tfinch2
Is there any particular reason you are reading the digits off two at a time or for only an even amount of digits?

The program is supposed to interpret the numbers as ascii and print out letters to the user. There's some adding and subtracting to be done with those numbers as well bcuz its supposed to be an encryption. But that's the idea. I just gotta pull out the numbers two at a time and modifiy them, then print their ascii equivalent.
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
print the result of the two digits you read after the recursive call returns