Saturday, October 22, 2011

a c program to reverse number

#include<stdio.h>
#include<conio.h>
#include<math.h>

main(){
       long int num,i,a,b;
       printf("Enter an integer:\n");
       scanf("%ld",&num);
       b=num;
      
       for(i=1; ;++i){
                          a=b%10;
                          printf("%ld",a);
                          b=b/10;
                         
                          if(b==0)
                             break;
                         
                         
                          }
                
                
                
      getch();
      }                
       

1 comment:

  1. Reversing the digits of a number means reversing the sequence of digits in a number.
    Befor reverse : 25346
    After reverse : 64352
    We can also reverse digits of a number using recursion

    ReplyDelete