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


Please Help Members By Posting Answers For Below Questions

What is c definition?

746


Explain how can I write functions that take a variable number of arguments?

616


Why are algorithms important in c program?

620


Why is c not oop?

539


Explain what does it mean when a pointer is used in an if statement?

617






What is the function of volatile in c language?

668


4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.

1727


Where can I get an ansi-compatible lint?

642


What is the difference between int main and void main?

575


When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.

1531


write a programming in c to find the sum of all elements in an array through function.

1708


How can I dynamically allocate arrays?

594


Why do we need a structure?

590


‎How to define structures? · ‎

630


What will the code below print when it is executed?   int x = 3, y = 4;         if (x = 4)                 y = 5;         else                 y = 2;         printf ("x=%d, y=%d ",x,y);

1358