I want to find the numbers between A and B that can be diveded by C using flowgorithm or a math formula.
As of now I can only output the numbers between the two given numbers.
I want to get the results and be able to average them and sum them.
Edit: I am trying to learn maths for obvious reasons and trying to understand the points of it, where to use what and formulas. Even though I tried, I couldn't find an information about how to solve this problem of mine on the internet. So my point is, I don't anyone to write the code for me, I just want to learn how to write it and what is logic behind it as I litteraly have no other sources at the moment. Thanks, if you take your time and help me.
It is hard to write a formula for this problem that will work in all computer languages, since the languages differ in how they treat integer division. Some languages have the modulo operator and some do not. But here is a hint to get started.
You definitely want the first number that is greater than or equal to
Athat is divisible byC. I'll assume thatA,B, andCare positive integers--if that is not the case, things get more complicated and depend more on the computer language. Then the formula iswhere
ceilis the "ceiling" function--rounding up to an integer. Most languages have this function. Note that you will need to test if this number is greater thanB.You also want the last number in your range that is divisible by
C, which iswhere
floorrounds down to an integer. Some languages useintrather thanfloor. Again, you will need to test if this number is less thanA. Some languages have a modulo operator%--if so, you could also useGiven those limits and the spacing
Cyou should be able to create an array with all your desired numbers.