#include <iostream>
#include <math.h>
using namespace std;
int
main ()
{
int x, y, z;
cout <<
"This program finds the number of multiples of any number among other two.\n";
cout <<
"Enter the number to which you want to find the multiples\n";
cin >> z;
cout <<
"Enter the first number:\n";
cin >> x;
cout <<
"Now, enter the second number:\n";
cin >> y;
if (y>z and x>z and z*z>x and z*z>y)
{
cout <<
"Has " << fabs((x - y) / z) - 1 << " multiples of " << z << " between " << x << " and " << y << endl;
}
if (x<z)
{
cout <<
"Has " << fabs((x - y) / z) + 1 << " multiples of " << z << " between " << x << " and " << y << endl;
}
if (y<z)
{
cout <<
"Has " << fabs((x - y) / z) + 1 << " multiples of " << z << " between " << x << " and " << y << endl;
}
if (x>z and z*z<x and z*z<y)
{
cout <<
"Has " << fabs((x - y) / z) << " multiples of " << z << " between " << x << " and " << y << endl;
}
if (y>z and z*z<x and z*z<y)
{
cout <<
"Has " << fabs((x - y) / z) << " multiples of " << z << " between " << x << " and " << y << endl;
}
/*if (x<y, x<z)
{
cout << z*(1*(y/z) + (y/z*(y/z - 1))/2);
}
if (x>y, y<z)
{
cout << z*(1*(x/z) + (x/z*(x/z - 1))/2);
}
if (y>z and x>z and y>x)
{
cout << z*( x/z * (y/z - x/z + 1) + ( y/z * (y/z - x/z)) / 2 );
}
if (y>z and x>z and y<x)
{
cout << z*( y/z * (x/z - y/z + 1) + ( x/z * (x/z - y/z)) / 2 );
} */
return 0;
}
glr, esse é meu código pra falar os a quantidade de múltiplos de um número entre outros dois, e dps mostrar a soma deles. a parte em comentário é porque a expressão está errada, pois quando a divisão da decimal, eu tenho q considerar o inteiro e somar um, mas n sei fzr. enfim, se puderem me ajudar ou tiverem dicas para melhorar o código.. valeu