-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp.cpp
49 lines (37 loc) · 894 Bytes
/
p.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//# program to generate a sequence of length l from the elemnts in array A
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
void generate_sequence(int * A, int n, int len,int *B,int k){
if(len==0) {
for(int i=0;i<k;i++)
cout<<B[i]<<" ";
cout<<endl;}
else{
int i=0;
while(i<n){
B[k-len]=A[i];
generate_sequence(A,n,len-1,B,k);
i++;
}
}
}
int main()
{
//n=size of array A;
// Array A contains the integers which we are going to use to create sequence
//len = the length of sequence you wish to create
// B = the array where the created sequence will be stored
// k= size of array B, k=len (inital value of len )
int k,len,n;
cin>>n>>len;
k=len;
int *A=(int *)malloc( n*sizeof(int));
int *B=(int *)malloc( k*sizeof(int));
cout<<"Enter "<<n <<" array elements \n";
int i=0;
for(i;i<n;i++)
cin>>A[i];
generate_sequence(A,n,len,B,k);
return 0;
}