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



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

Answer / 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

More C Interview Questions

When is a void pointer used?

0 Answers  


What are the main characteristics of c language describe the structure of ac program?

0 Answers  


What is the correct declaration of main?

0 Answers  


In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

0 Answers  


How does C++ help with the tradeoff of safety vs. usability?

1 Answers  


Explain the process of converting a Tree into a Binary Tree.

0 Answers   Ignou,


what is the use of ~ in c lang?????

3 Answers  


Is c still used?

0 Answers  


coding for Fibonacci.?

1 Answers  


Explain about block scope in c?

0 Answers  


main() { int age; float ht; printf("Enter height and age"); scanf("%d%d",&height,&age); if((age<=20)&&(ht>=5)) {printf("She loves you");} else {printf("She loves you");} }

2 Answers  


is compiler do read the data line by line or not. ??

6 Answers   LG Soft, Satyam, Tech Mahindra,


Categories