Hello,
I need to know the code in C to write a function.
"Write a function that takes an integer value and returns the number with
its digits reversed. For example, given the number 7631, the function should
return 1367.
Printable View
Hello,
I need to know the code in C to write a function.
"Write a function that takes an integer value and returns the number with
its digits reversed. For example, given the number 7631, the function should
return 1367.
we usually don't do homework here so I'll only give a few hints: ask the
user to provide a number, convert the input number to a string, and then
reverse that string. display the result.
Danny
Ronin wrote:
>
> Hello,
>
> I need to know the code in C to write a function.
> "Write a function that takes an integer value and returns the number with
> its digits reversed. For example, given the number 7631, the function should
> return 1367.
I would say using mod 10, get the last digit
and then divide the input by 10,continues to
mod and divide until zero.
Then, you reverse the order of the integers
and return the value.
bababa
>Ronin wrote:
>>
>> Hello,
>>
>> I need to know the code in C to write a function.
>> "Write a function that takes an integer value and returns the number with
>> its digits reversed. For example, given the number 7631, the function
should
>> return 1367.
I would say using mod 10, get the last digit
and then divide the input by 10,continues to
mod and divide until zero.
Then, you reverse the order of the integers
and return the value.
bababa
>Ronin wrote:
>>
>> Hello,
>>
>> I need to know the code in C to write a function.
>> "Write a function that takes an integer value and returns the number with
>> its digits reversed. For example, given the number 7631, the function
should
>> return 1367.
"Ronin" <ronin_21_2000@hotmail.com> wrote:
>
>Hello,
>
>I need to know the code in C to write a function.
>"Write a function that takes an integer value and returns the number with
>its digits reversed. For example, given the number 7631, the function should
>return 1367.
Convert it to a string.
Use standard string manipulation functions to reverse the string
If you are using MFC CString::MakeReverse will work nicely.
Convert it back to an integer using atoi or something similar.
"Andy" <Andy@Charter.net> wrote:
>
>"Ronin" <ronin_21_2000@hotmail.com> wrote:
>>
>>Hello,
>>
>>I need to know the code in C to write a function.
>>"Write a function that takes an integer value and returns the number with
>>its digits reversed. For example, given the number 7631, the function should
>>return 1367.
>
>Convert it to a string.
>
>Use standard string manipulation functions to reverse the string
>If you are using MFC CString::MakeReverse will work nicely.
>
>Convert it back to an integer using atoi or something similar.
>
>
Try:
int i, CurNum, NewNum ;
for( i = CurNum, NewNum = 0 ; i > 0 ; i /= 10 )
{ NewNum = ( NewNum * 10 ) + i % 10 ; }
It works...;)