Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int verificare (int i,int x[])
- {
- int j;
- if (i>1 && abs((float)x[i]-(float)x[i-1])!=2)
- return 0;
- return 1;
- }
- void generare (int n,int x[],int i,int aux)
- {
- if (i<=n)
- {
- aux=aux*10+x[i];
- generare (n,x,i+1,aux);
- }
- else
- cout<<aux<<endl;
- }
- void prel_2 (int n,int x[],int i)
- {
- int j;
- for (j=1;j<=9;j=j+2)
- {
- x[i]=j;
- if (verificare (i,x))
- if (i<n)
- prel_2 (n,x,i+1);
- else
- generare (n,x,1,0);
- }
- }
- int main()
- {
- int n,x[100];
- cout<<"n=";cin>>n;
- prel_2(n,x,1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement