MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / findsum

Function findsum

GeeksForGeeks/Sister_and_Coins/Solution.cpp:7–16  ·  view source on GitHub ↗

This function finds whether the amount can be given to Mila or not i.e. if any sum of coins with gila equals amount to be distributed(x) */

Source from the content-addressed store, hash-verified

5 i.e. if any sum of coins with gila equals amount to be distributed(x)
6*/
7bool findsum(int a[],int n,int sum)
8{
9 if(sum==0)
10 return 1;
11 if(sum!=0 && n==0 ) // If there are no coins and n is greater than 0, then no solution exist
12 return 0;
13 if(a[n-1]>sum) // i.e. a[n-1] can't be included in solution
14 return findsum(a,n-1,sum);
15 return (findsum(a,n-1,sum)||findsum(a,n-1,sum-a[n-1])); // is sum of solutions including a[n-1] or excluding a[n-1]
16}
17
18int money(int a[],int n,int m,int sum)
19{

Callers 1

moneyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected