Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Hamming.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include<stdio.h>
#include<string.h>
void main()
{
int d,c,i, length, count = 0,n;
int s1[100], s2[100];
printf("length of s1 and s2 \n");
scanf("%d",&n);
printf("Enter s1 : ");
for(i=0;i<n;i++)
{
scanf("%d", &s1[i]);
}
printf("Enter s2 : ");
for(i=0;i<n;i++)
{
scanf("%d", &s2[i]);
}
for(i=0;i<n;i++)
{
if(s1[i]!=s2[i])
{
count=count+1;
}
}

printf("\nHamming Distance : %d\n", count);
if(count==0)
{
printf("no error ");
}
else
{

d=count-1;
c=(count-1)/2;
printf("error bits that can be detected = %d\n",d);
printf("error bits that can be corrected= %d",c);
}

getch();
}
49 changes: 49 additions & 0 deletions anagram.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// C++ program to check if two strings
// are anagrams of each other
#include <bits/stdc++.h>
using namespace std;
#define NO_OF_CHARS 256

bool areAnagram(char* str1, char* str2)
{
// Create a count array and initialize all values as 0
int count[NO_OF_CHARS] = { 0 };
int i;

// For each character in input strings, increment count
// in the corresponding count array
for (i = 0; str1[i] && str2[i]; i++) {
count[str1[i]]++;

count[str2[i]]--;

}

// If both strings are of different length. Removing
// this condition will make the program fail for strings
// like "aaca" and "aca"
if (str1[i] || str2[i])
return false;

// See if there is any non-zero value in count array
for (i = 0; i < NO_OF_CHARS; i++)
if (count[i])
return false;
return true;
}

// Driver code
int main()
{
char str1[] = "geeks@forgeeks";
char str2[] = "for@geeksgeeks";

// Function call
if (areAnagram(str1, str2))
cout << "The two strings are anagram of each other";
else
cout << "The two strings are not anagram of each "
"other";

return 0;
}