Last active
December 15, 2015 09:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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