-
Notifications
You must be signed in to change notification settings - Fork 0
/
tobin
52 lines (46 loc) · 804 Bytes
/
tobin
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
50
51
52
#include <stdio.h>
void tobin(int arr[],int n,int k,int trigger){
if(n==1){
for(int i=0;i<(trigger-1);i++){
printf("%d",arr[i]);
}
if(k==1){
printf("1\n");
}
else{
printf("0\n");
}
}
else if(k==0){
for(int i=0;i<(trigger-n);i++){
printf("%d",arr[i]);
}
for(int i=0;i<n;i++){
printf("0");
}
printf("\n");
}
else if(n==k){
for(int i=0;i<(trigger-n);i++){
printf("%d",arr[i]);
}
for(int i=0;i<n;i++){
printf("1");
}
printf("\n");
}
else{
arr[trigger-n]=1;
tobin(arr,n-1,k-1,trigger);
arr[trigger-n]=0;
tobin(arr,n-1,k,trigger);
}
}
int main() {
int n,k;
scanf("%d %d",&n,&k);
int trigger=n;
int arr[trigger];
tobin(arr,n,k,trigger);
return 0;
}