Advertisement
Guest User

Problema 2

a guest
Oct 23rd, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int verificare (int i,int x[])
  7. {
  8. int j;
  9. if (i>1 && abs((float)x[i]-(float)x[i-1])!=2)
  10. return 0;
  11. return 1;
  12. }
  13. void generare (int n,int x[],int i,int aux)
  14. {
  15. if (i<=n)
  16. {
  17. aux=aux*10+x[i];
  18. generare (n,x,i+1,aux);
  19. }
  20. else
  21. cout<<aux<<endl;
  22. }
  23. void prel_2 (int n,int x[],int i)
  24. {
  25. int j;
  26. for (j=1;j<=9;j=j+2)
  27. {
  28. x[i]=j;
  29. if (verificare (i,x))
  30. if (i<n)
  31. prel_2 (n,x,i+1);
  32. else
  33. generare (n,x,1,0);
  34. }
  35. }
  36. int main()
  37. {
  38. int n,x[100];
  39. cout<<"n=";cin>>n;
  40. prel_2(n,x,1);
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement