
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Using iterative function print the given number in reverse order in C language
Problem
How to print the given in reverse order with the help of iterative function i.e., while loop using C programming language?
Solution
So far, we had seen how to reverse the string using string function and without string function, now let’s see how to reverse a number without using predefined function −
Algorithm
Input − give a number at runtime
Step 1: Declare the variable number,reverse Step 2: Initialize reverse= 0 Step 3: while number>0 (a) reverse=reverse*10 + number%10; reverse = reverse*10 + num%10; (b) Divide number by 10 Step 4: return reverse
Example
#include <stdio.h> int reverse(int number){ int reverse = 0; while(number > 0){ reverse = reverse*10 + number%10; number = number/10; } return reverse; } int main(){ int number; printf("enter a number:"); scanf("%d",&number); printf("Reverse of no. is %d", reverse(number)); getchar(); return 0; }
Output
enter a number:356789 Reverse of no. is 987653
- Related Articles
- Print the last k nodes of the linked list in reverse order Iterative approach in C language
- Print the alternate nodes of linked list (Iterative Method) in C language
- Print the last k nodes of the linked list in reverse order Recursive Approaches in C language
- C Program to reverse a given number using Recursive function
- Reverse a String (Iterative) C++
- Write a C program to print the message in reverse order using for loop in strings
- How to print list values in reverse order using Collections.reverse() in Android?
- Java program to print the reverse of the given number
- Print all subsequences of a string using Iterative Method in C++
- Print reverse of a Linked List without actually reversing in C language
- Print a given matrix in reverse spiral form in C++
- How to print the elements in a reverse order from an array in C?
- How to print one dimensional array in reverse order?
- Print Leaf Nodes at a given Level in C language
- Printing the numbers in reverse order using Division and modulo operators using C

Advertisements