Skip to content

Instantly share code, notes, and snippets.

@joaorafaelm
Created June 22, 2014 22:08
Show Gist options
  • Save joaorafaelm/0778e0fecdc54be1e7b4 to your computer and use it in GitHub Desktop.
Save joaorafaelm/0778e0fecdc54be1e7b4 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int calculateValor(int valor, int sub);
int main()
{
int valor;
int sub[] = {100, 50, 20, 10, 2, 1};
puts("DIGITE UM VALOR:");
if (scanf("%i", &valor) == 1) {
for (int i = 0; i < sizeof(sub); ++i){
valor = calculateValor(valor, sub[i]);
}
}else puts("Número Inválido!");
}
int calculateValor(int valor, int sub){
int count;
count = 0;
while (valor >= sub)
{
valor = valor - sub;
count = count + 1;
}
printf("Notas de %i : %i\n", sub, count);
if(valor == 0) exit(0); else return valor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment