Thursday, December 5, 2019

PROGRAMMING IN C TO PRINT DIGIT OF ENTERED NUMBER IN REVERSE ORDER ?

C program to reverse a number


C program to reverse a number and to print it on the screen. For example, if the input is 123, the output will be 321. In the program, we use the modulus operator (%) to obtain digits of the number. To invert the number write its digits from right to left.

 C program to find     reverse of a number

#include <stdio.h>

int main()
{
  int n, r = 0;

  printf("Enter a number to reverse\n");
  scanf("%d", &n);

  while (n != 0)
  {
    r = r * 10;
    r = r + n%10;
    n = n/10;
  }

  printf("Reverse of the number = %d\n", r);

  return 0;
}

OUTPUT WILL WE :


2 comments: