0

write a c++ program to reverse a digits

qn

9th Sep 2016, 5:12 PM
athira kurian
6 Respuestas
+ 2
http://code.sololearn.com/cO0Ai4pZ9W1C #include <iostream> using namespace std; unsigned int reverseDigits(unsigned int n) { int i, m; m = 0; while (n != 0) { m = m*10 + n%10; n = n/10; } return m; } int main() { unsigned int n; cout << "Reverse digits" << endl; cout << "Please enter a number: "; cin >> n; cout << n << endl; cout << reverseDigits(n) << endl; return 0; }
9th Sep 2016, 11:42 PM
Zen
Zen - avatar
+ 1
#include <iostream> using namespace std; int main() { long int dig,i,rev; cout<<"Enter the digit\t:: "; cin>>dig; // reversing digit cout<<"The reversed digit is \t:"<<endl; for(i=1;dig!=0;i*=1){ rev=dig%10; dig/=10; cout<<rev; } return 0; }
9th Sep 2016, 6:05 PM
Chinmay Majumdar
Chinmay Majumdar - avatar
0
u can simple use string functions to reverse digits
2nd Oct 2016, 1:30 PM
Pankaj Rawat
Pankaj Rawat - avatar
0
u want to reverse string or numbers?
2nd Oct 2016, 1:30 PM
Pankaj Rawat
Pankaj Rawat - avatar
0
Let getReversedNumber(N) is a function, which returns reverse of N. Then, we can use recursion to reverse the digits if a number using below mention recursive equation. getReversedNumber(N) = (N%10)X pow(10, (log10(N/10) + 1)) + getReversedNumber(N/10) Here is the c program to reverse a number using recursion http://www.techcrashcourse.com/2015/03/c-program-to-reverse-number-using-recursion.html Reversing a number using loop while(number != 0){ rightDigit = number % 10; reverse = (reverse * 10) + rightDigit; number = number/10; } http://www.techcrashcourse.com/2014/10/c-program-reverse-number.html
15th Apr 2017, 5:58 AM
Arun Kumar
Arun Kumar - avatar
- 3
#include<iostream.h> int maun() { int a=5,i; for(i=0;i<=a;i++) { cout<<a<<endl; a--; } return 0; }
9th Sep 2016, 5:55 PM
Ismaeel Siddiqui
Ismaeel Siddiqui - avatar