WAP using a separate function to reverse a given integer number. Say 1234 converted into 4321.
#include<stdio.h> #include<math.h> int main() { int a,b; printf("Enter the integer = "); scanf("%d",&a); b=reverse(a); ///reverse function call // printf("\nReverse number of %d is %d ",a,b); printf("\n\n"); } int reverse(int x) { int i,j,k,y; y=0; i=0; while(x>0) { i=x%10; /// modulos of x y=(y*10)+i; /// multiply 10 to y and adding i x=x/10; ///take example of 123 } return y; }
WAP using a separate function to reverse a given integer number. Say 1234 converted into 4321.
Reviewed by Unknown
on
03:34
Rating:
No comments: