Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

anagram in c language, Exercises of Algorithms and Programming

girilen 2 kelimenin anagram olup olmadıgını veren program

Typology: Exercises

2018/2019

Uploaded on 12/12/2019

halil-ibrahim-camur
halil-ibrahim-camur 🇹🇷

2 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include <stdio.h>
int check_anagram(char [], char []);
int main()
{
char a[100], b[100];
printf("Enter a string\n");
gets(a);
printf("Enter a string\n");
gets(b);
if (check_anagram(a, b) == 1)
printf("The strings are anagrams.\n");
else
printf("The strings aren't anagrams.\n");
return 0;
}
int check_anagram(char a[], char b[])
{
int first[26] = {0}, second[26] = {0}, c=0;
// Calculating frequency of characters of the first string
pf2

Partial preview of the text

Download anagram in c language and more Exercises Algorithms and Programming in PDF only on Docsity!

#include <stdio.h> int check_anagram(char [], char []); int main() { char a[100], b[100]; printf("Enter a string\n"); gets(a); printf("Enter a string\n"); gets(b); if (check_anagram(a, b) == 1) printf("The strings are anagrams.\n"); else printf("The strings aren't anagrams.\n"); return 0; } int check_anagram(char a[], char b[]) { int first[26] = {0}, second[26] = {0}, c=0; // Calculating frequency of characters of the first string

while (a[c] != '\0') { first[a[c]-'a']++; c++; } c = 0; while (b[c] != '\0') { second[b[c]-'a']++; c++; } // Comparing the frequency of characters for (c = 0; c < 26; c++) { if (first[c] != second[c]) return 0; } return 1; }