fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. double grn[] = {1.24, 0.56, .32, 1, 4.2};
  6. size_t nom[] = {25, 10, 5, 1};//мають буди відсоротовані по зменшенню
  7. size_t grn_size = sizeof(grn) / sizeof(grn[0]);
  8. size_t nom_size = sizeof(nom) / sizeof(nom[0]);
  9. for( size_t i = 0; i < grn_size; i++ )
  10. {
  11. size_t dif = grn[i]*100;
  12. size_t cnt = 0;
  13. cout<<grn[i]<<" : "<<endl;
  14. for( size_t j = 0; dif && (j < nom_size); j++)
  15. {
  16. cnt = dif / nom[j];
  17. cout<<nom[j]<<" = "<<cnt<<endl;
  18. dif -= cnt*nom[j];
  19. }
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
1.24 : 
25 = 4
10 = 2
5 = 0
1 = 4
0.56 : 
25 = 2
10 = 0
5 = 1
1 = 1
0.32 : 
25 = 1
10 = 0
5 = 1
1 = 2
1 : 
25 = 4
4.2 : 
25 = 16
10 = 2