Programa en C++ que devuelve la inversa de un numero.

Posted on Monday 23 April 2007

Aquí va un programa que si le entras un numero entero, de lo devuelve en orden inverso:

#include<iostream>
using namespace std;

int inv(int n);
void inter(int x,int y);
//main
int main(void){
int n;
cin>>n;
cout<<endl<<inv(n)<<endl;
system("PAUSE");
}
//funcio auxiliar per elevar enters.
int pou(int b,int e){
int i,r=1;
for(i=0;i<e;i++){
r*=b;
}
return(r);
}
//funcio invierte
int inv(int n){
int s=n,c=0,i,t,x;
while(s>0){
c++;
s/=10;
}
for(i=0;i<c;i++){
x=n/(pou(10,i))%10;
t=t*10+x;
}
return(t);
}

Nota: Se precisa de un compilador C++ para compilar; puedes descargarte uno aquí (gratis)




No comments have been added to this post yet.

Leave a comment

(required)

(required)


Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.


:smile: :grin: :razz: :lol: :wink: :mrgreen: :neutral: :roll: :shock: :???: :cool: :oops: :twisted: :evil: :eek: :mad: :sad: :cry: :!: :idea: :arrow:

RSS feed for comments on this post | TrackBack URI