how to find anagram without using string functions using
only loops in c programming

Answer Posted / csnr

#include<stdio.h>

int check(char [], char []);

main()
{
char a[100], b[100];
int flag;

printf("Enter first string\n");
gets(a);

printf("Enter second string\n");
gets(b);

flag = check(a, b);

if ( flag == 1 )
printf("\"%s\" and \"%s\" are anagrams.\n", a, b);
else
printf("\"%s\" and \"%s\" are not anagrams.\n", a, b);

return 0;
}

int check(char a[], char b[])
{
int first[26] = {0}, second[26] = {0}, 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;
}

Is This Answer Correct ?    11 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I write a function that takes a format string and a variable number of arguments?

600


What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }

1953


How is = symbol different from == symbol in c programming?

607


write a program fibonacci series and palindrome program in c

630


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

629






swap 2 numbers without using third variable?

656


FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.

1198


Explain how do you list files in a directory?

614


write a proram to reverse the string using switch case?

2461


How can I read data from data files with particular formats?

599


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

3728


Why isn't it being handled properly?

643


How do I get an accurate error status return from system on ms-dos?

644


Write a C program to count the number of email on text

1412


write a program to input 10 strings and compare without using strcmp() function. If the character of one string matches with the characters of another string , sort them and make it a single string ??? example:- str1="Aakash" st2="Himanshu" str="Uday" output:- Aakashimanshuday (please post the answer as quickly as possible)

1623