2
Read two numbers being y greater than x, calculate the sum of the numbers pairs of that range of numbers, including the numbers typed; calculate and show the multiplication of the odd numbers of this range, including those typed;
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main ()
{
setlocale(LC_ALL, "PORTUGUESE");
int X=0, Y=0,somapar=0, cont=0, impar;
printf("Insira o VALOR DE X: ");
scanf("%d", &X);
printf("Insira o VALOR DE Y: ");
scanf("%d", &Y);
if (Y>X)
{
for (cont=X; cont<=Y; cont++)
{
cont;
if (cont%2==0)
{
somapar = somapar + cont;
}
else
{
impar = impar * cont;
}
}
}
else
{
printf("X não pode ser maior que Y\n");
}
printf("A soma dos números pares nesse intervalo é %d\n", somapar);
printf("A multiplicação dos números impares nesse intervalo é %d\n", impar);
system ("pause");
return 0;
}
Putting 0 to X and 10 to Y, the output shows only the sum of even numbers that gives 30, but the multiplication gives zero.
I thought I already tried that kkkkkkkkkk was, thanks!!!
– R. ANA