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
write a program that declares an array of 30 elements named "income" in the main functions. then cal and pass the array to a programmer-defined function named "getIncome" within the "getIncome" function, ask the user for annual income of 30 employees. then calculate and print total income on the screen using the following function: "void getIncome ( ai []);
What is pointer to pointer in c with example?
How is a macro different from a function?
What does c in a circle mean?
What is a double c?
If errno contains a nonzero number, is there an error?
What are lookup tables in c?
What's the best way of making my program efficient?
write a c program thal will find all sequences of length N that produce the sum is Zero, print all possible solutions?
What is pragma in c?
Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.
what is event driven software and what is procedural driven software?
Explain function?
How is pointer initialized in c?
write a progrmm in c language take user interface generate table using for loop?