C Program to reverse the digits of a number using recursion Last Updated : 29 Nov, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an integer N, the task is to reverse the digits of given integer using recursion. Examples: Input: N = 123Output: 321Explanation:The reverse of the given number is 321. Input: N = 12532Output: 23521Explanation:The reverse of the given number is 23521. Approach: Follow the steps below to solve the problem: Recursively iterate every digit of N.If the current value of N passed is less than 10, return N. if(num < 10) return N; Otherwise, after each recursive call (except the base case), return the recursive function for next iteration: return reverse(N/10) + ((N%10)*(pow(10, (floor(log10(abs(N))))))) where, floor(log10(abs(x))) gives the count of digits of x ((x%10)*(pow(10, (floor(log10(abs(x))))))) places the extracted unit place digits (x%10) to their desired positions Below is the implementation of the above approach: C // C program for the above approach #include <math.h> #include <stdio.h> #include <stdlib.h> // Function to reverse the digits of // the given integer int reverse(int N) { return ((N <= 9)) ? N : reverse(N / 10) + ((N % 10) * (pow(10, (floor(log10( abs(N))))))); } // Utility function to reverse the // digits of the given integer void reverseUtil(int N) { // Stores reversed integer int result = reverse(N); // Print reversed integer printf("%d", result); } // Driver Code int main() { // Given integer N int N = 123; // Function Call reverseUtil(N); return 0; } Output:321 Time Complexity: O(log10N)Auxiliary Space: O(log10N) for call stack Write a C Program to Reverse a Number Comment More infoAdvertise with us Next Article Print a long int in C using putchar() only N notavacillator Follow Improve Article Tags : C Language Similar Reads Program to Reverse a String using Pointers Given a string, the task is to reverse this String using pointers. Examples:Input: GeeksOutput: skeeGInput: GeeksForGeeksOutput: skeeGroFskeeGApproach: This method involves taking two pointers, one that points at the start of the string and the other at the end of the string. The characters are then 2 min read C Program to print numbers from 1 to N without using semicolon? How to print numbers from 1 to N without using any semicolon in C. C #include<stdio.h> #define N 100 // Add your code here to print numbers from 1 // to N without using any semicolon What code to add in above snippet such that it doesn't contain semicolon and prints numbers from 1 to N?We stro 2 min read C Program to Reverse Array of Strings Given an array of string literals, reverse the array. Examples: Input : arr[] = {"Coding", "Never", "Fail", "Me"} Output : arr[] = {"Me", "Fail", "Never", "Coding"} Input : arr[] = {"welcome", "to", "geeksforgeeks"} Output : arr[] = {"geeksforgeeks", "to", "welcome"} The idea is to create an array o 1 min read Print a long int in C using putchar() only Write a C function print(n) that takes a long int number n as argument, and prints it on console. The only allowed library function is putchar(), no other function like itoa() or printf() is allowed. Use of loops is also not allowed. We strongly recommend to minimize the browser and try this yoursel 2 min read Convert a floating point number to string in C Write a C function ftoa() that converts a given floating-point number or a double to a string. Use of standard library functions for direct conversion is not allowed. The following is prototype of ftoa(). The article provides insight of conversion of C double to string. ftoa(n, res, afterpoint) n -- 3 min read Convert Decimal to Binary in C In this article, we will learn to write a C program to convert a decimal number into a binary number. The decimal number system uses ten digits from 0 to 9 to represent numbers and the binary number system is a base-2 number system that uses only 0 and 1 to represent numbers. Algorithm to Convert De 2 min read Like