Solu?ie: #include <stdio.h> #include <stdlib.h> #include <string.h> char* s; char* s2; int N = 0, S = 0; int sir[100]; int produs() { char *c = strdup(s); int num1, num2; char op; num1 = atoi(strdup(s)); while (*s >= '0' && *s <= '9') s++; op = *s; while (op == '*') { s++; num2 = atoi(strdup(s)); while (*s >= '0' && *s <= '9') s++; op = *s; num1 *= num2; } return num1; } int suma() { int t1, t2; char op; int sgn = 1; if (*s == '-') { sgn = -1; } *s++; t1 = produs(); t1 *= sgn; op = *s++; while (op == '+' || op == '-') { t2 = produs(); switch (op) { case '+': t1 += t2; break; default : t1 -= t2; break; } op = *s++; } return t1; } void eval(int n) { int i; if (n == 2*N) { s = strdup(s2); if (suma() == S && *s2 != '*') printf("%s\n",s2); } else { char c[100]; for (i = 0; i < 3; i++) { itoa(sir[n/2],c,10); switch(i) { case 0: s2[n] = '+'; break; case 1: s2[n] = '-'; break; case 2: s2[n] = '*'; break; } s2[n+1] = '\0'; itoa(sir[n/2],c,10); strcat(s2,c); eval(n+2); } } } int main() { s=(char*) malloc(100*sizeof(char)); s2=(char*) malloc(100*sizeof(char)); int i; scanf("%d",&N); for (i = 0; i < N; i++) scanf("%d",&sir[i]); scanf("%d",&S); eval(0); return 0; } L.E. E valabil codul de mai sus ?i pentru opera?ii de împ?r?ire, în expresia dat? cu urm?toarele modific?ri: int produs() { char *c = strdup(s); int num1, num2; char op; num1 = atoi(strdup(s)); while (*s >= '0' && *s <= '9') s++; op = *s; while (op == '*') { s++; num2 = atoi(strdup(s)); while (*s >= '0' && *s <= '9') s++; op = *s; [COLOR="#FFFF00"]switch(op) { case '*': num1 *= num2; break; case '/': num1 /= num2; break; }[/COLOR] } return num1; } ?i void eval(int n) { int i; if (n == 2*N) { s = strdup(s2); if (suma() == S && *s2 != '*' [COLOR="#FFFF00"]&& *s2 != '/'[/COLOR]) printf("%s\n",s2); } else { char c[100]; for (i = 0; i < 3; i++) { itoa(sir[n/2],c,10); switch(i) { case 0: s2[n] = '+'; break; case 1: s2[n] = '-'; break; case 2: s2[n] = '*'; break; } s2[n+1] = '\0'; itoa(sir[n/2],c,10); strcat(s2,c); eval(n+2); } } }