What is the input?

I have a question that is asking what the inputs would have to be for inputs k, n, r to get the output of 2 3 4 5 from the code below.

do you know the algebra or formula i would end up using?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

#include <iostream>
using namespace std;


int main()
{
int j, k, n, r;
cin >> k >> n >> r; 

for (j=k; j<=n;j++)
cout << r*j<<" ";


    return 0;
}
Last edited on
The output can never be (2 3 4 5).

Proof.
The number of outputs printed by the for loop is even.
The last cout adds only one more and thus makes the total number of outputs odd.
(2 3 4 5) has an even number of outputs which is something our program cannot produce.
sorry, i forgot to mention that its asking what are the inputs for k, n, r to get the output of 2 3 4 5
Last edited on
cout << r*j<<" ";
Since j increases by 1 each time through the loop, this will output values separated by r. If the output is 2,3,4,5 this separation is ..., so r is ... <you fill in the blanks>.

Once you have r, then the first and last values will give you k=... and n=... <again, you fill in the blanks>.
Topic archived. No new replies allowed.