-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagram.c
More file actions
53 lines (46 loc) · 1.16 KB
/
Copy pathAnagram.c
File metadata and controls
53 lines (46 loc) · 1.16 KB
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
53
#include<stdio.h>
#include <stdlib.h>
int main()
{
char s1[255], s2[255];
printf("Input the string 1: ");
scanf("%s", s1);
printf("Input the string 2: ");
scanf("%s", s2);
if(strlen(s1) != strlen(s2)){
printf("Not an Anagram");
return 0;
}
for(int k = 0; k < strlen(s1); k++){
s1[k] = tolower(s1[k]);
}
for(int k = 0; k < strlen(s2); k++){
s2[k] = tolower(s2[k]);
}
for(int k = 0; k < strlen(s1)-1; k++){
for(int j = 0; j < strlen(s1)-k-1; j++){
if(s1[j] > s1[j+1]){
char temp = s1[j];
s1[j] = s1[j+1];
s1[j+1] = temp;
}
}
}
for(int k = 0; k < strlen(s2)-1; k++){
for(int j = 0; j < strlen(s2)-k-1; j++){
if(s2[j] > s2[j+1]){
char temp = s2[j];
s2[j] = s2[j+1];
s2[j+1] = temp;
}
}
}
for(int j = 0; j < strlen(s2); j++){
if(s1[j] != s2[j]){
printf("Not Anagram.");
return 0;
}
}
printf("It's an Anagram.");
return 0;
}