Question:

write an algorithm to reverse a four digit number

by Guest3615  |  12 years, 9 month(s) ago

0 LIKES UnLike

write an algorithm to reverse a four digit number

 Tags: Algorithm, digit, Reverse, write

   Report

2 ANSWERS

  1. jane
    Hello,

    Its a java algorithm

    public class Reverse {
    static public void main(String args[]) throws Exception {
    long n = Long.parseLong(args[0]);
    for (long i=10; n>0; i*=10) {
    long remainder = n%i;
    System.out.print(remainder * 10 / i);
    n -= remainder;
    }
    System.out.println("");
    }
    }

    Please post your question in detail

    hope it helps

  2. Guest1943
    // YOUR WELCOME!

    #include <iostream>
    #include <iomanip>
    #include <fstream>
    using namespace std;


    int reverse(int);


    int main()
    {
        int n, answer;
        
        
        cout << "Enter an integer" << endl;
        cin >> n;
        
        answer = reverse(n);
        
      
        cout << answer;
        system ("pause");
        return 0;
    }

    int reverse(int n)
    {
        int answer = 0;
        while(n > 0) {
          
           answer = (answer * 10) +(n % 10);
           n/=10;
          
            
        }
        return answer;
    }
Sign In or Sign Up now to answser this question!

Question Stats

Latest activity: 14 years, 6 month(s) ago.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.