Difference between revisions of "Solução: Bits Trocados - OBI (Jandson Nunes)"

From AdonaiMedrado.Pro.Br
Jump to: navigation, search
(New page: <code lang="c"> #include <stdio.h> int main () { int valor, cedulas[4] = {0}, teste = 1, i; scanf("%d", &valor); while (valor){ while (valor >= 50){ cedulas[0]++; valor -= 50;...)
 
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
 
scanf("%d", &valor);
 
scanf("%d", &valor);
 
while (valor){
 
while (valor){
while (valor >= 50){
+
cedulas[0] = valor / 50;
cedulas[0]++;
+
valor = valor%50;
valor -= 50;
+
cedulas[1] = valor/10;
}
+
valor = valor%10;
while (valor >= 10){
+
cedulas[2] = valor/5;
cedulas[1]++;
+
valor = valor%5;
valor -= 10;
+
}
+
while (valor >= 5){
+
cedulas[2]++;
+
valor -= 5;
+
}
+
 
cedulas[3] = valor;
 
cedulas[3] = valor;
 
valor = 0;
 
valor = 0;

Latest revision as of 13:49, 29 April 2009

#include <stdio.h>
 
int main () {
	int valor, cedulas[4] = {0}, teste = 1, i;
 
	scanf("%d", &valor);
	while (valor){
		cedulas[0] = valor / 50;
		valor = valor%50;
		cedulas[1] = valor/10;
		valor = valor%10;
		cedulas[2] = valor/5;
		valor = valor%5;
		cedulas[3] = valor;
		valor = 0;
		printf("Teste %d\n", teste);
		for (i = 0; i < 4; i++){
			printf("%d ", cedulas[i]);
			cedulas[i] = 0;
		}
		printf("\n\n");
		scanf("%d", &valor);
		teste++;
	}
}