25 lines
		
	
	
		
			510 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			510 B
		
	
	
	
		
			C
		
	
	
	
	
	
#include <stdio.h>
 | 
						|
 | 
						|
int main() {
 | 
						|
    const int troco = 387;
 | 
						|
    const int moedas[] = {100, 50, 25, 10, 5, 1};
 | 
						|
    int valor = 0;
 | 
						|
    int moedasfinal = 0;
 | 
						|
    for (int i = 0; i < 6; i++) {
 | 
						|
      while (valor < troco) {
 | 
						|
        valor += moedas[i];
 | 
						|
        moedasfinal += 1;
 | 
						|
        if (valor > troco) {
 | 
						|
          valor -= moedas[i];
 | 
						|
          moedasfinal -= 1;
 | 
						|
          break;
 | 
						|
        } else if (valor == troco) {
 | 
						|
          printf("%d\n", moedasfinal);
 | 
						|
          break;
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
    return 0;
 | 
						|
 | 
						|
}
 |