Guest User

Untitled

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int x[10],a[10],n,s;
  4. void afisare(int n)
  5. {
  6. for(int i=1;i<=n;i++)
  7. cout<<a[x[i]]<<",";
  8. cout<<"\b";
  9. cout<<endl;
  10. }
  11. void back(int i,int sr)
  12. {int sn=0;
  13. for(int j=x[i-1]+1;j<=n;j++)
  14. {
  15. x[i]=j;
  16. sn=sr-a[j];
  17. if(sn==0)
  18. afisare(i);
  19. else if(i<n && sn>0)
  20. back(i+1,sn);
  21. }
  22. }
  23. int main()
  24. {
  25. cout<<"Dati numarul N si suma S";
  26. cin>>n>>s;
  27. for(int i=1;i<=n;i++)
  28. cin>>a[i];
  29. back(1,s);
  30. }
Add Comment
Please, Sign In to add comment