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

Why c is called procedure oriented language?

0 Answers  


write a program to copy a string without using a string?

2 Answers  


What is c token?

0 Answers  


What is integer constants?

0 Answers  


What is the difference between char array and char pointer?

0 Answers  






which will be first in c compiling ,linking or compiling ,debugging.

3 Answers   Sonata,


What is void pointers in c?

0 Answers  


1.find the second maximum in an array? 2.how do you create hash table in c? 3.what is hash collision

9 Answers   HCL, Qualcomm,


please tell me the logic for this C program : INPUT (string):ABCD OUTPUT :BCDA CDAB DABC

2 Answers   Mphasis,


Explain function pointer with exapmles.

2 Answers  


Why doesnt that code work?

0 Answers  


Why cd or dvd are round why not square.

1 Answers  


Categories