Varianta 94 / Subiectul 3 / Problema 4 |
#include<fstream.h> ifstream f("numar.in"); void main() { long n; int aux,i,c1,c2,a[10],nr=0; f>>n; cout<<endl; while(n/10 && n%10<n/10%10) { nr++; a[nr]=n%10; n=n/10; } if(n<10) cout<<"nu exista"; else { nr++; a[nr]=n%10; n=n/10; c1=n%10; n=n/10; i=1; while(a[i]<c1) i++; c2=i; aux=c1; c1=a[c2]; a[c2]=aux; n=n*10+c1; for(i=1;i<=nr;i++) n=n*10+a[i]; cout<<n; } } |