Hi Friends,
I found the solution and thought to share it here.
if we take a character array as the input, you can read any number of
digits.
next thing is to subtract each of the digit from '0' which is 48(ascii of
'0').
Then, you can print from the last index till the start index of the array.
In this way, you don't have to do the mathematical operations % and /.
Thanks
On Jan 29, 2008 9:02 AM, Jincy Jacob <[EMAIL PROTECTED]> wrote:
> Hi friends,
> I have written a simple program to reverse a number.The code is pasted
> below:
> #include<stdio.h>
> int main()
> {
> int num, rem ,i =0;
> printf("Enter a number:");
> scanf("%d", &num);
> printf("The reversal is:");
> /* For two, three upto nine digits*/
> while(num != 0)
> {
> rem = num%10;
> num = num/10;
> printf("%d",rem);
> }
> Then i realized that the above program will reverse only numbers upto 10
> digits. Can anyone tell me a solution to get rid of this limit?
> Now, I read i/p(number) from command line argv[] as a string.
>
[Non-text portions of this message have been removed]