given a positive integer n ,we have to find the number of possible combination of integers (i,j) where i+j=k ... given 0<=i,j,k<=n
i code this problem as below ...
#include<iostream.h>
#include<conio.h>
void max(int n,int x,int k,int *no)
{
if(x>=0)
{
max(n,x-1,k,no);
if(n+x==k)
{
(*no)+=1;
cout<<"\n"<<" The combinations are formed by "<<n<<" "<<x;
}
return;
}
if(n>=0)
max(n-1,n-1,k,no);
return;
}
void main()
{
clrscr();
int x,k,n,*no;
no=new int();
*no=0;
cout<<"enter k :";
cin>>k;
cout<<"\n enter n : ";
cin>>n;
max(n,n,k,no);
cout<<"\nTotal number is : "<<*no;
getch();
}
can anyone help in improving the time complexity of this problem ???