This blog is under construction

Wednesday, 19 June 2013

C program to find reverse of a given number

Write a C program to find reverse of the given number.


  #include <stdio.h>
  int main() {
        int data, mod, res = 0;
        printf("Enter the value for data:");
        scanf("%d", &data);

        /* find reverse of the given number */
        while (data > 0) {
                mod  = data % 10;
                res  = (res * 10) + mod;
                data = data / 10;
        }

        printf("Reverse of the given number: %d\n", res);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter the value for data:19876
  Reverse of the given number: 67891



1 comment:

  1. if i given 100 as data then what will be the output for reverse number

    ReplyDelete