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

how to print the character with maximum occurence and print that number of occurence too in a string given ?

0 Answers   Microsoft,


Differentiate fundamental data types and derived data types in C.

0 Answers   HCL,


how to create c progarm without void main()?

1 Answers   NIIT,


What is pointer to pointer in c with example?

0 Answers  


what are the advantage and disadvantage of recursion

5 Answers  






What is const volatile variable in c?

0 Answers  


write a reverse string to print a stars.(with out using logic) ***** **** *** ** *

2 Answers  


what is the answer for it main() { int i; clrscr(); printf("%d",&i)+1; scanf("%d",i)-1; }

3 Answers  


What is the difference between memcpy and memmove?

0 Answers  


1)which of following operator can't be overloaded. a)== b)++ c)?! d)<=

16 Answers   CybOrg, Siemens,


What are the characteristics of arrays in c?

0 Answers  


What is getch?

0 Answers  


Categories