3
I made a program to calculate within a sequence the sum of the positive numbers and the sum of the negative numbers. When I use the command while
, the idea is that it is within a sequence of 7 numbers, and then the program leaves the while
and make condition, but this is not happening.
Follows code below:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<locale.h>
int n, num, somaPositivo, somaNegativo, i;
int main ()
{
setlocale(LC_ALL, "portuguese");
printf("\n Digite o tamanho da sequência: ");
scanf("%f",&n);
somaPositivo = 0;
somaNegativo = 0;
i = 1;
while (i <= n)
{
printf("\n Digite um número da sequência: ");
scanf("%f",&num);
}
if (num > 0)
{
somaPositivo = somaPositivo + num;
}
else
{
somaNegativo = somaNegativo + num;
}
i = i + 1;
printf("\n A soma dos números positivos da sequência é: \n",somaPositivo);
printf("\n A soma dos números negativos da sequência é: \n",somaNegativo);
}
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.
– Maniero