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 ctrl c called?

586


please help me..... please codes and flowchart plz turbo c lang po yan.....please asap response... 3. Make an astrology program. The user types in his or her birthday (month, day, and year as integer), and the program responds with the user’s zodiac sign, horoscope, and other information related to it. If the user’s birth year falls into a leap year, your program should display an appropriate message for it. NOTES: Conditional Statements: it should be with graphics

2854


the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above

598


What is a far pointer in c?

590


Do pointers take up memory?

647






What are the primitive data types in c?

563


Where static variables are stored in memory in c?

519


How can I run c program?

677


What is static and volatile in c?

773


Which is better pointer or array?

592


What’s a signal? Explain what do I use signals for?

599


if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0

1439


How can I find the modification date and time of a file?

596


Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.

1011


What is restrict keyword in c?

638