samedi 28 novembre 2015

How to swap first and last digit in number in c++

please help me I am writing this code but it shows 0

#include <iostream>
using namespace std;

int main() {

    int n,a,b;
    cin>>n;
    b=n%10;

    while(n!=0) {
        a=n%10;
        n=n/10;     
    }
    a=b;
    b=a;
    cout<<n<<endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire