Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Feb 19th, 2018 50 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top