I am making a program in which the program takes 3 numbers as input: "l", "r" and "a". I get all the values of "x" between l and r, (l and r inclusive). example, l = 1, r = 3, x values are 1, 2, 3. so now I have a function, f(n) = ((x/a) + (x % a)),(note: [x/a] is rounded down to an integer). so I have implemented this in c++ and my code is below.
#include<iostream>
using namespace std;
int main()
{
int l;
int r;
int a;
cin>>l>>r>>a;
int nums[(r-l)+2];
int answers[(r-l)+2];
for (int i = 1; i < (r-l)+2; i++)
{
nums[i] = i;
}
for (int i = 1; i < sizeof(nums)/sizeof(nums[0])-1; i++)
{
answers[i] = ((nums[i]/a) + (nums[i] % a));
}
int j = 0;
j = answers[0];
for (int i = 0; i < sizeof(answers); i++)
{
if (j < answers[i])
{
j = answers[i];
}
}
cout<<j;
}
but whenever I run this code, I get huge random numbers like 230984084 and all.So please point out what's wrong with my Code. Thanks in advance.