unique, ad-free, freemium downloads

8 December 2017

How To Print Numbers in Reverse Order (Easy and simple)

PRINTING NUMBERS IN REVERSE ORDER:

An easy way of printing integers in revere order in C is as follows:

CODE:

#include <stdio.h>

int main()
{   int num;
    printf("\n\tPlease enter the number: ");
    scanf("%d",&num);//Number should be positive integer
    printf("\n\tDigits in reverse are: ");
    while(num>0)
    {
        printf("\t%d ",num % 10); //To print the last digit
        num /= 10; //To eliminate the last digit
    }
    printf("\n\n");
    getch();
    return 0;
}

OUTPUT:

No comments:

Post a Comment