Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added hamming.c and updated the corresponding README.md (#39)
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @author: Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com> | ||
* @github: https://github.com/razdeep | ||
* @date: 24/12/2018 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
int hammingDistance(const char *first_word, const char *second_word) | ||
{ | ||
int count = 0; | ||
if (strlen(first_word) != strlen(second_word)) | ||
{ | ||
return -1; | ||
} | ||
for (int i = 0; i < strlen(first_word); i++) | ||
{ | ||
if (first_word[i] != second_word[i]) | ||
{ | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
int main() | ||
{ | ||
char first_word[100], second_word[100]; | ||
printf("Enter the first word: "); | ||
scanf("%s", first_word); | ||
printf("Enter the second word: "); | ||
scanf("%s", second_word); | ||
printf("The hamming distance between %s and %s is: %d\n", first_word, second_word, hammingDistance(first_word, second_word)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters