Advertisement
Dani_info

pb 20/59

Nov 26th, 2017
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. using namespace std;
  3. int x[100],pus[100],n,p,nr=0, suma=0;
  4. void Write(int p){
  5.  for(int i=1;i<=p;i++){
  6.  cout<<x[i];
  7.  }
  8.  int a=0;
  9.  for(int i=1;i<=p;i++)
  10.  a=a*10+x[i];
  11.  suma=suma+a;
  12.  nr++;
  13. }
  14. void Aranj(int k, int p){
  15.  for(int i=1;i<=9;i=i+2){
  16.  if(!pus[i]){
  17.  x[k]=i;
  18.  pus[i]=1;
  19.  if(k==p){
  20.  Write(p);
  21.  cout<<" ";
  22.  }
  23.  else
  24.  Aranj(k+1,p);
  25.  pus[i]=0;
  26.  }
  27.  }
  28. }
  29. int main(){
  30.  cout<<"Dari numarul maxim de cifre (de la 1 la 5) ";
  31.  cin>>n;
  32.  for(p=1;p<=n;p++)
  33.  Aranj(1,p);
  34.  cout<<endl<<"Suma este "<<suma<<" din "<<nr<< " numere"<<endl;
  35.  
  36.  return 0;
  37. }
Advertisement
RAW Paste Data Copied
Advertisement