The Hamming distance between two equal-length strings of symbols is the number of positions at which the corresponding symbols are different
In other words, it measures the minimum number of substitutions required to change one string into the other, or the minimum number of errors that could have transformed one string into the other. In a more general context, the Hamming distance is one of several string metrics for measuring the edit distance between two sequences. It is named after the American mathematician Richard Hamming.
Aim:- Write a Program to Find Hamming Distance.
C Program Code:
#include<stdio.h>
#include<iostream.h>
#include<string.h>
void main()
{
int i, length, count = 0;
char v1[8], v2[8];
clrscr();
printf("\nWrite a Program to Find Hamming Distance\n");
printf("Enter 1st String : ");
scanf("%s", &v1);
printf("Enter 2nd String : ");
scanf("%s", &v2);
length = strlen(v2);
for(i = 0; i < length; i++)
{
if(v1[i] != v2[i])
{
count++;
}
}
printf("\nHamming Distance : %d", count);
getch();
}
Also Read - C program to count total words in text
2 Comments
This code has errors
ReplyDeleteCould you please share details of error?
Delete