From f55e9a65de955f8852079357bc2d1922a307e88f Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Mon, 1 Oct 2018 18:55:07 +0530 Subject: [PATCH] bug freed reverse.c and organized --- reverse.cpp | 25 ------------------------- reverse/reverse.c | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 25 deletions(-) delete mode 100644 reverse.cpp create mode 100644 reverse/reverse.c diff --git a/reverse.cpp b/reverse.cpp deleted file mode 100644 index 4a16e6fb..00000000 --- a/reverse.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include ; - - -int reversDigits(int num) -{ -static int rev_num = 0; -static int base_pos = 1; -if(num > 0) -{ - reversDigits(num/10); - rev_num += (num%10)*base_pos; - base_pos *= 10; -} -return rev_num; -} - -/*Driver program to test reversDigits*/ -int main() -{ - int num = 4562; - printf("Reverse of no. is %d", reversDigits(num)); - - getchar(); - return 0; -} diff --git a/reverse/reverse.c b/reverse/reverse.c new file mode 100644 index 00000000..a85071c3 --- /dev/null +++ b/reverse/reverse.c @@ -0,0 +1,21 @@ +#include + +int reversDigits(int num) +{ + int rev_num = 0; + while(num) + { + rev_num = (rev_num*10) + num%10; + num /= 10; + } + return rev_num; +} + +int main() +{ + int num; + printf("Enter any number: "); + scanf("%d", &num); + printf("Reverse of no. is %d\n", reversDigits(num)); + return 0; +}