If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Need help in writing function in C.

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.

Re: Need help in writing function in C.

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.

Re: Need help in writing function in C.

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.

Re: Need help in writing function in C.

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.

Re: Need help in writing function in C.

"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.

Re: Need help in writing function in C.

"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.
>
>