I think the logic of this program is right, but the result is going wrong.
Make a program that receives two numbers X and Y, where X < Y. Calculate and show:
- the sum of the even numbers of this range of numbers, including the numbers entered;
- multiplication of odd numbers in this range, including digits
Code:
#include <stdio.h>
void main()
{
int x = 0, y = 0, somaPares = 0, multiImpares = 0;
scanf("%d", &x);
scanf("%d", &y);
somaPares = (x+y);
multiImpares = (x*y);
printf("%d\n", somaPares);
printf("%d\n", multiImpares);
while (x<y)
{
x++;
if(x%2==0){
somaPares = somaPares + x;
}
else {
multiImpares = multiImpares*x;
}
}
printf("A soma de X e Y mais os números pares entre eles é: %d\n", &somaPares);
printf("A multiplicação de X e Y mais os números ímpares entre eles é: %d", &multiImpares);
}
The input that I am putting is 5 and 3, being 8 the sum and 15 the result, in the first two printfs
is coming correct, now in the last two printfs
are returning me respectively, 2752260 and 2752256.