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
Where does the name "C" come from, anyway?
How do you write a program which produces its own source code as output?
What is mean by data types in c?
Is c high or low level?
What is the difference between text and binary i/o?
How can I split up a string into whitespace-separated fields?
Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?
what are non standard function in c
Can we initialize extern variable in c?
What is hashing in c?
What are the 4 data types?
How can I prevent another program from modifying part of a file that I am modifying?
Whats s or c mean?
how to capitalise first letter of each word in a given string?
How do you print an address?