Skip to content

Instantly share code, notes, and snippets.

@fernandoguedes
Last active December 15, 2015 09:59
Show Gist options
  • Save fernandoguedes/5242743 to your computer and use it in GitHub Desktop.
Save fernandoguedes/5242743 to your computer and use it in GitHub Desktop.
1. Criar um flag de saída quando o número digitado for 0. a) Dizer quantos números são positivos; b) Dar o percentual de números negativos.
#include <stdlib.h>
#include <stdio.h>
main() {
int nPositivos, nNegativos, n, cont;
float porcNegativos;
nPositivos = 0;
cont = 0;
porcNegativos = 0;
nNegativos = 0;
do {
printf("Informe um numero:\n");
scanf("%f", &n);
if (n > 0) {
nPositivos++;
cont++;
} else {
nNegativos++;
cont++;
}
}
while (n != 0);
porcNegativos = (nNegativos * 100)/cont;
printf("Qtd de numeros positivos: %d\n", nPositivos);
printf("Percentual de numeros negativos: %.2f", porcNegativos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment