This is my code....

``````#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int t,i,j,k,m,n,o,q=0,a,b,c;

cin>>n;
cin>>k;
i=n+1;
j=k-1;
for(a=n+1;a<=k-1;a++)
{
for(b=i;b<=j;b++)
{
m=a*b-n;
n=a-n;
o=b-n;
t=n*o;
c=m%t;
if(c==0)
{
m=0;
n=0;
o=0;
q++;
}
else
{
m=0;
n=0;
o=0;
break;
}
}
}
cout<<q;

getch();
return 0;
}``````

whats wrong with it?
Input:
Input will be two numbers by which I have to find the number of pairs (a,b) which will be considered the condition....
(a*b-n) is divisible by (a-n) and (b-n).
Like....
n=1 and k=5
The output will be....
2, because (2,2) and (3,3) are the expected pairs.

In the beginning you said cin n and k, but what exactly are the values of those variables? Without values you will get nothing out.

In the beginning you said cin n and k, but what exactly are the values of those variables? Without values you will get nothing out.

I have to take value of n and k like 1 and 8 respectively.

I don't understand what you mean, n needs a number and k needs a number, that's all there is to it.

int n and k are using by the for loops.Then whats wrong with it?

Yes but you are saying n+1 and k-1, so what is n and k? There is no answer to n+1 if n doesn't have a value. And you can't say cin >> k without asking for it to be entered. I've tried compiling your program and it just gives a blank screen so that should mean something.

And you can't say cin >> k without asking for it to be entered.

This is false. Just because there's no prompt doesn't mean the program isn't waiting for input.

I've tried compiling your program and it just gives a blank screen so that should mean something.

It means you should enter two values. :icon_rolleyes: Sure, adding a prompt will make the program more user-friendly, but that's not a requirement.

Well sorry to say but that's just bad programming style, I mean how was I suppose to know

Well sorry to say but that's just bad programming style

I don't disagree.

I mean how was I suppose to know

Well, you could...you know, READ THE CODE. But seriously, how helpful can you be if you don't understand what the code is doing?

I don't disagree.

Well, you could...you know, READ THE CODE. But seriously, how helpful can you be if you don't understand what the code is doing?

Well, I did...you know, READ THE CODE. But I'm just not use to coding in that way and forgive me if I compile it and nothing happens. And I was in the end the only one trying to help.

Well, I did...you know, READ THE CODE.

Perhaps I should have said "understand the code", since you read it but clearly didn't understand it. :) But now you know and can actually run the program until it has a division by zero error.

Always a pleasure

All other bickering aside ;), it looks like a big part of the problem might be your re-use of variable n at line 19. Each time through the inner loop, you re-assign n based on loop-variable a and the previous value of n. I don't think that's what you meant to do. Looping over a and b is probably fine, though I'm not sure why you loop over a using n+1 and k-1, and then loop over b using i and j (which are assigned to be those same two values). But inside those loops, you may want to call a function such as:

``````bool productHasFactors(int a, int b, int n)
{
...
}``````

which determines if a*b-n is divisible by a-n and b-n, and returns true or false accordingly.

Also, as Cross213 suggested, you may wish to add a prompt at line 9, such as `cout << "Enter lower and upper bounds for the search: ";`

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.