Created
February 5, 2016 13:09
-
-
Save thegreatshasha/7912b15fe39e3e67201c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char op[]={'+','-','*','/'}; | |
bool eval(int a[],int target,int n,int pos,int prev) | |
{ | |
if(pos == n) { | |
if(prev == target) { | |
return true; | |
} | |
return false; | |
} | |
for(int i=0;i<;4;i++) { | |
int res = 0; | |
char ch = op[i]; | |
if(ch == '+') { | |
res = prev + a[pos]; | |
} else if(ch == '-') { | |
res = prev - a[pos]; | |
} else if(ch == '*') { | |
res = prev * a[pos]; | |
} else { | |
res = prev / a[pos]; | |
} | |
if( eval(a,target,n,pos+1,res ) ) | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment