Hamming Distance between two strings | C ++ program to find hamming distance b / w two string ; function to calculate Hamming distance ; driver code ; function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int hammingDist ( char * str1 , char * str2 ) { int i = 0 , count = 0 ; while ( str1 [ i ] != ' \0' ) { if ( str1 [ i ] != str2 [ i ] ) count ++ ; i ++ ; } return count ; } int main ( ) { char str1 [ ] = " geekspractice " ; char str2 [ ] = " nerdspractise " ; cout << hammingDist ( str1 , str2 ) ; return 0 ; }