• API
• FAQ
• Tools
• Archive
daily pastebin goal
25%
SHARE
TWEET

Untitled

gustavofont Jan 12th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2. #include <stdlib.h>
3. #include <math.h>
4.
5. int main()
6. {
7.     double  preco , troco = 1.0 , resto ;
8.     int centavos50 = 0, centavos25 = 0 , centavos10 = 0 , centavos5 = 0 , centavos1 = 0;
9.     printf("Digite o preco do produto (menor que 1 real) \n");
10.     scanf("%lf",&preco);
11.     troco = troco - preco;
12.     printf("O troco e igual a : %.2f centavos \n" , troco);
13.     centavos50 = (int)(troco / 0.5);
14.     resto = troco - centavos50 * 0.5;
15.     centavos25 = (int)(resto / 0.25);
16.     resto = resto - centavos25 * 0.25;
17.     centavos10 = (int)(resto / 0.10);
18.     resto = resto - centavos10 * 0.10;
19.     centavos5 = (int)(resto / 0.05);
20.     resto = resto - centavos5 * 0.05;
21.     centavos1 = (int)round((resto / 0.01));
22.
23.     if(centavos50 != 0)
24.         printf("%d moedas de 50 centavos \n", centavos50);
25.     if(centavos25 != 0)
26.         printf("%d moedas de 25 centavos \n", centavos25);
27.     if(centavos10 != 0)
28.         printf("%d moedas de 10 centavos \n", centavos10);
29.     if(centavos5 != 0)
30.         printf("%d moedas de 5 centavos \n", centavos5);
31.     if(centavos1 != 0)
32.         printf("%d moedas de 1 centavo \n", centavos1);
33.
34.     return 0;
35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top