marcelofoxes

URI 1021 - Wrong Answer

May 24th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <float.h>
  4.  
  5. int main(int argc, char const *argv[])
  6. {
  7.     double notes[] = {100.00, 50.00, 20.00, 10.00, 5.00, 2.00, 1.00, 0.50, 0.25, 0.10, 0.05, 0.01};
  8.  
  9.     double monetary_value;
  10.     scanf("%lf", &monetary_value);
  11.    
  12.     int i;
  13.     for (i = 0; i < (sizeof(notes)/sizeof(double)); ++i) {
  14.         double note_or_coin = notes[i];
  15.         double note_or_coins_count = monetary_value / note_or_coin;
  16.  
  17.         monetary_value = fmod(monetary_value, note_or_coin);
  18.  
  19.         if (note_or_coin == 100.00) {
  20.             printf("NOTAS:\n");
  21.         } else if (note_or_coin == 1.00) {
  22.             printf("MOEDAS:\n");
  23.         }
  24.  
  25.         // get the right value before floor(ing)
  26.         note_or_coins_count = note_or_coins_count + fmod(note_or_coins_count, 0.01);
  27.  
  28.         printf("%.0f %s(s) de R$ %.2f\n", floor(note_or_coins_count), (note_or_coin >= 2.00) ? "nota" : "moeda", note_or_coin);
  29.  
  30.     }
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment