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
Compare interpreters and compilers.
What are the string functions? List some string functions available in c.
When should volatile modifier be used?
Give the rules for variable declaration?
How do I use strcmp?
Differentiate between the = symbol and == symbol?
What are local static variables? How can you use them?
Explain the difference between structs and unions in c?
Explain how can you check to see whether a symbol is defined?
What is const keyword in c?
What are lookup tables in c?
What is wrong with this statement? Myname = 'robin';
What is #error and use of it?
What do you mean by a sequential access file?
Explain the properties of union.