Hamming distance d(v1 ,v2)=3 if v 1=011011,v2=110001.
Example :-
#include<stdio.h>
#include<string.h>
int main()
{
int i,l1,l2,count=0;
char one[200],two[200];
while(1)
{
printf("Enter First String ::\n");
scanf("%s",&one);
printf("Enter Second String ::\n");
scanf("%s",&two);
l1=strlen(one);
l2=strlen(two);
if(l1!=l2)
{
printf("\nLength of both strings must be same, enter again!\n");
}
else
{
for(i=0;i<l1;i++)
{
if(one[i]!=two[i])
{
count++;
}
}
break;
}
}
printf("\nHamming distance :-\t%d",count);
return 0;
}
OUTPUT
Enter First String ::
Coding
Enter Second String ::
Blocks
Hamming distance :- 6
Coding
Enter Second String ::
Blocks
Hamming distance :- 6
No comments:
Post a Comment
Please do not any spam link in Comment Box