Anagrams Program in C Programming

Image result for c programming

Anagrams Program in C Programming
Code:
  #include<stdio.h>
#include<string.h>
int main(){
  char s1[200],s2[200];
  int first[26]={0},second[26]={0},c=0,i,flag=0;
    //int l,l1;
  printf("Enter the first string\n");
  gets(s1);
  printf("Enter the second string\n");
  gets(s2);

    while(s1[c]!='\0')
    {
      first[s1[c]-'a']++;
      c++;
    }
    c=0;
    while(s2[c]!='\0')
    {
      second[s2[c]-'a']++;
      c++;
    }
    for(i=0;i<26;i++){
      if(first[i]!=second[i])
        flag=1;
    }
   
  if(flag==0)
    printf("%s and %s are anagrams",s1,s2);
  else
    printf("%s and %s are not anagrams",s1,s2);

  return 0;
}

No comments