Răspuns :
#include<iostream>
#include<math.h>
using namespace std;
int GetSize(int Nr);
int GetNrByPlace(int Nr,int Loc);
int main(){
int n=0,Temp=0,
MaxNr=0,
Loc=1;
cin>>n; Temp=n;
while(n!=0){
for(int x=1;x<=GetSize(n);x++){
if(GetNrByPlace(n,x)>MaxNr){
MaxNr=GetNrByPlace(n,x);
Loc=x;
}
}
if(MaxNr!=0) {
cout<<MaxNr<<",";
n-=(int)MaxNr*pow(10,(double)Loc-1) ;
MaxNr=0;
}
}
//============If n had a 0 or more add them========
n=Temp;
for(int x=1;x<=GetSize(n);x++){
if(GetNrByPlace(n,x)==0) cout<<"0,";
}
system("pause");
return 0;
}
int GetSize(int Nr){
int Size=0;
while(Nr!=0){
Size++; Nr/=10;
}
return Size;
}
int GetNrByPlace(int Nr,int Loc){
int Count=0;
while(Nr!=0){
Count++;
if(Count==Loc) {
return Nr%10;
continue;
}
Nr/=10;
}
}
#include<math.h>
using namespace std;
int GetSize(int Nr);
int GetNrByPlace(int Nr,int Loc);
int main(){
int n=0,Temp=0,
MaxNr=0,
Loc=1;
cin>>n; Temp=n;
while(n!=0){
for(int x=1;x<=GetSize(n);x++){
if(GetNrByPlace(n,x)>MaxNr){
MaxNr=GetNrByPlace(n,x);
Loc=x;
}
}
if(MaxNr!=0) {
cout<<MaxNr<<",";
n-=(int)MaxNr*pow(10,(double)Loc-1) ;
MaxNr=0;
}
}
//============If n had a 0 or more add them========
n=Temp;
for(int x=1;x<=GetSize(n);x++){
if(GetNrByPlace(n,x)==0) cout<<"0,";
}
system("pause");
return 0;
}
int GetSize(int Nr){
int Size=0;
while(Nr!=0){
Size++; Nr/=10;
}
return Size;
}
int GetNrByPlace(int Nr,int Loc){
int Count=0;
while(Nr!=0){
Count++;
if(Count==Loc) {
return Nr%10;
continue;
}
Nr/=10;
}
}
Vă mulțumim pentru vizita pe site-ul nostru dedicat Informatică. Ne dorim ca informațiile furnizate să vă fi fost utile. Dacă aveți întrebări sau aveți nevoie de suport suplimentar, nu ezitați să ne contactați. Revenirea dumneavoastră ne bucură, iar pentru acces rapid, adăugați-ne la favorite!