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:

3 Ans BPSC Assistant Programmer Lab Aptitude test Programs and Queries with Proper solution (Taken By BCC)

2 Ans BPSC aptitude test all programs solutions here

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

1 Ans Write a C program for Interest Calculation

2 Ans Train Location Message TR Train_Code and Send to 16318 Example: TR 705 Send to 16318

1 Ans A C Program to split a number into digits

1 Ans Write a C program to print Fibonacci number using recursion

2 Ans BPSC Programming Aptitude Lab Test Important programs

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

1 Ans Write a C program to print Floyd Triangle