Skip to content

Instantly share code, notes, and snippets.

@sreedharmb
Created September 16, 2012 06:06
Show Gist options
  • Save sreedharmb/3731221 to your computer and use it in GitHub Desktop.
Save sreedharmb/3731221 to your computer and use it in GitHub Desktop.
You are given an integer s and an integer k. Find k positive integers a1, a2, ..., ak such that their sum is equal to s and their product is the maximal possible.
int product(int s,int k)
{
int temp=0;
int i,max;
if(k==1)
return s;
else
{
for(i=1;i<s;i++)
{
max=i*product(s-i,k-1);
if(max>temp)
temp=max;
}
return temp;
}
}
@sachinthange1
Copy link

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment