Jump to content
The Striker

Inversul unui numar

Recommended Posts

1. Cerinta:

 Se dă un număr n de la tastatură. Să se afișeze inversul acestuia.

-  Exemplu:

n=123
Inversul este:321

2. Rezolvare:

#include <iostream>
using namespace std;


int main()
{
    int n, inv=0, c;
    cout << "Introdu un numar:";  cin >> n;
    while (n != 0)
    {
        c = n % 10;
        inv = inv * 10 + c;
        n = n / 10;
    }
    cout <<"Inversul este: "<< inv;
    system("Pause");
    return 0;
}

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Who's Online   0 Members, 0 Anonymous, 2 Guests (See full list)

    There are no registered users currently online

×

Important Information

This site uses cookies. By continuing browsing, you agree to the use of this information. For more details, see Terms of Use and Privacy Policy.