How to write a C Program Anagrams in C Programming Language ?
Considering a string will only contain lower-case alphabets. It can also be done for uppercase letters , digits , special characters etc.
Solution:
- #include<stdio.h>
- #include<stdbool.h>
- #include<string.h>
- bool isAnagram(char *str1,char *str2)
- {
- int alphabetCount[26] = {0};
- int i = 0;
- if(strlen(str1) != strlen(str2))
- return false;
- for(i=0;str1[i]!='\0';++i)
- {
- ++alphabetCount[str1[i]-'a'];
- --alphabetCount[str2[i]-'a'];
- }
- for(i=0;i<26;++i)
- {
- if(alphabetCount[i])
- return false;
- }
- return true;
- }
- int main(void)
- {
- char string1[1001],string2[1001];
- /*
- considering a string will only contain lower-case alphabets
- It can also be done for uppercase letters , digits , special characters etc.
- */
- gets(string1);
- gets(string2);
- if(isAnagram(string1,string2))
- printf("yes");
- else
- printf("no");
- return 0;
- }
Learn More :
String
- Write a c program to check given string is palindrome number or not.
- C Program to Convert Text String to Binary
- C Program String - Alphabet Count Example
- C Program String Example
- C Program String Count Example
- C Program String Example
- C Program to Print a String Without Use Semicolon.
- C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters
- C Program To Find Length Of String And Concatenate Two Strings
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program To Print String In Formatted Output Form
- C Program To Reverse The String Using Pointer
- C Program Concatenating Two Strings Into A Third System
- C Program Date from string DDDD-DD-DD
- BUILDS A STRING FROM THE LSB BITS OF EACH PIXEL
- C Program Finds Sub-String Search in String
- C Program to concatenate two strings without using string functions
- C Program to Count Vowels, Consonants and Spaces in a string
- C Program to convert a string to upper case
- C Program Performs a search and replace for a specified target and replacement string
- C Program to find string length without library function
- C Program to Check Given String is Palindrome or Not
- C Program to Converts a Number to a String.
- Design a C function that shortens a string to 8 characters
Special Characters
Lower Case
- How To Write a C program that reads your first and last names and then converts them to upper-case and lower-case letters. The results will be printed to standard output console.
- Lower-Upper Case/Positive-Negative Integer
- C Program to Recursively converts all file-names to lower-case
- C Program to accept string from user & convert all lower case letters into upper case letters & vice versa
Anagrams
Letter
Digit
- C Program To Find Reverse Of Any Digit Number
- C Program To Print Sum Of n Digit Number
- C Program To Add Digits Of Entered Number
- C Program to Sum of The First and Last Digit Of 'n' Digit Number
- C Program to Sum of First and Last Digits of a Four-Digit number
- C Program to Sum of digits of a Five Digit Number
- C Program to Reversing a Five Digit Integer Number
- C Program to Sum Up Digits Of A Number
- Input Number and Calculate Sum of it's Digits C Program
Upper Case
- How To Write a C program that reads your first and last names and then converts them to upper-case and lower-case letters. The results will be printed to standard output console.
- C Program To Print Text Into Uppercase
- Lower-Upper Case/Positive-Negative Integer
- C Program to convert a string to upper case
- C Program to accept string from user & convert all lower case letters into upper case letters & vice versa