Program to Reverse a given Number

Output:

4321

You may also like...

9 Responses

  1. Anonymous says:

    It would be helpfull if every line’s function is explained.

  2. LearnCOnline says:

    The statement while(num!=0) will be executed till value of num !=0
    num%10 (read as num mod 10) will return the last digit.
    So in 1st iteration, it will return 4.
    So newNum will become–> 0*10 + 4 –>4
    next line i.e. num/10 will return 123

    2nd Iteration:
    newNum=4*10 + (num%10)–>4*10 + 3 –>43
    num = 123/10 = 12

    This loop continues until value of num becomes zero.
    Hope its clear.

  3. Dennis says:

    Ya !! This is an interesting website that i have ever searched
    I like its tutorials very much..

  4. Anonymous says:

    #include
    #include
    #include
    #include

    void main()
    {
    int num1, num2;
    char str[10];
    clrscr();

    printf(“\nEnte the Number : “);
    scanf(“%d”,&num1);

    sprintf(str,”%d”,num1);

    strrev(str);

    num2 = atoi(str);

    printf(“\nReversed Number : “);
    printf(“%d\n”,num2);
    getch();
    }
    (i think itz btr)

  5. Anonymous says:

    what about the reverse of a string????

  6. Anonymous says:

    Good explanation for reverse the number

  7. LearnCOnline says:

    Thank you everyone for the wonderful comments. I hope this website is helping every one out there.

    If you like this website, kindly share it with everyone.

    Thanks,
    LearnCOnline Team

  8. shanth says:

    while(num!=0){
    rev=num%10;
    num=num/10;
    }
    print rev and watch

Leave a Reply

Your email address will not be published. Required fields are marked *