Skip to content

Commit

Permalink
Added hamming.c and updated the corresponding README.md (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Razdeep committed Dec 24, 2018
1 parent 28e09ea commit 4181774
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Day3/C/hamming.c
@@ -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;
}
43 changes: 43 additions & 0 deletions Day3/README.md
Expand Up @@ -132,6 +132,49 @@ public class HammingDistance {
return 0;
}
```
## C Implementation
### [hamming.c](./C/hamming.c)
```c
/**
* @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;
}
```
## Why Hamming Distance?

The #1 reason for not being successful is inconsistency, and it is a common trend that people start something and on give up on the third day itself, and one of the major reasons behind that is that they find it difficult to continue. 
Expand Down

0 comments on commit 4181774

Please sign in to comment.