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
Why double pointer is used in c?
What is an identifier?
What is the difference between far and near ?
Explain what is the difference between functions getch() and getche()?
Is it better to use a macro or a function?
Explain what is the difference between #include and #include 'file' ?
What is the use of ?
Why flag is used in c?
In C programming, how do you insert quote characters (‘ and “) into the output screen?
Are pointers integers in c?
why wipro wase
Can you explain the four storage classes in C?
What is structure padding and packing in c?
Write a code to generate divisors of an integer?
Where is volatile variable stored?