-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw02.c
34 lines (32 loc) · 824 Bytes
/
hw02.c
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
#include"stdio.h"
#include"string.h"
#include"malloc.h"
#include"math.h"
#include"stdlib.h"
void GenerateString(int n, char* string){
char *prev;
char *new;
int i;
prev = (char*)malloc(((1<<n) - 1) * sizeof(char));
new = (char*)malloc(((1<<n) - 1) * sizeof(char));
prev[0] = '\0';
new[1] = '\0';
for(i = 0; i < n; i++){
new[0] = 'a' + i;
strcat(string, new);
strcat(string, prev);
strcpy(prev, string);
printf("%s\n", string);
}
free(prev);
free(new);
}
int main(){
int n;
scanf("%d", &n);
char *ptr;
ptr = (char*)malloc(((1<<n) - 1) * sizeof(char));
GenerateString(n, ptr);
free(ptr);
return 0;
}