-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanagram.c
More file actions
50 lines (35 loc) · 714 Bytes
/
anagram.c
File metadata and controls
50 lines (35 loc) · 714 Bytes
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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/* works correct*/
void exchange(char *str, int x, int y){
char ch;
if(str[x] != str[y]){
ch = str[x];
str[x] = str[y];
str[y] = ch;
}
return;
}
void makeanagrams(char *str, int start){
/* print the current string*/
// printf("%s ::: %d \n ", str, start);
int i;
if(start == strlen(str) - 2){
exchange(str, start, start + 1);
printf("%s\n", str);
return;
}
for(i = start + 1; i < strlen(str); i++){
makeanagrams(str, start + 1);
exchange(str, start, i);
printf("%s ::: %d \n ", str, start);
}
return;
}
int main(){
char *str;
str = (char *)malloc(6*sizeof(char));
scanf("%s", str);
makeanagrams(str, 0);
}