Ask Question - Get Answer

1 Ans Write a C Program to check Anagrams of two strings

Asked by AL MaMun (4 Golds) Friday, 31 Jul 2020, 04:05 PM at (Education Tutorials)

Please log in to answer, like and save
0
Save 0

<<< Previous
Log in to Answer Next >>>

Answer(s):

A C program to Check Anagrams.


#include<stdio.h>

int check_anagram(char a[], char b[])

{

    int first[26]= {0};

    int second[26]= {0};

    int c=0;


    while(a[c]!='\0')

    {

        first[a[c]-'a']++;

        c++;

    }

    c=0;

    while(b[c]!='\0')

    {

        second[b[c]-'a']++;

        c++;

    }

    for(c=0; c<26; c++)

    {

        if(first[c]!=second[c])

            return 0;

    }

    return 1;

}

int main()

{

    char a[100], b[100];

    int flag;


    gets(a);

    gets(b);


    flag=check_anagram(a,b);

    if(flag==1)

        printf("%s and %s are anagrams", a, b);

    else

        printf("%s and %s are not anagrams", a, b);

    return 0;

}


Answered by AL MaMun (4 Golds) Friday, 31 Jul 2020, 04:06 PM

Please log in to Upvote, Downvote and Report
           

Related Q/A:

1 Ans Write a C program to print Floyd Triangle

1 Ans Write a C program to check a Palindrome Number

1 Ans Write a C program for Interest Calculation

1 Ans A C Program to split a number into digits

1 Ans Write a C Program to find factorial using recursion

1 Ans A Quest for Peace in the Middle East: Recent Perspectives - composition

1 Ans Write a C program to implement x power n using recursion

1 Ans Write a C program to implement Insertion sort data structure and algorithm

1 Ans Write a C program to find nth Fibonacci number

1 Ans Write a C program to find the highest and lowest number in a series