Write a program that computes number of vowels (letters a, e, o, i, y, u) in a g
ID: 3757670 • Letter: W
Question
Write a program that computes number of vowels (letters a, e, o, i, y, u) in a given word. You can assume that all letters in the word are in the lower case: Enter a words: university This word has 5 vowels. Write a program that removes vowels from a given word. You can assume that a\ letters in the word arc in the lower case: Enter a words: university With vowels removed: nvrst Write a program that prompts the user to enter two strings of the same length and computes the number of positions in which these two strings differ. This number is known as Hamming distance between the two strings. You need to write the code using only string operations explicitly mentioned in class. Enter the first string: hotel Enter the second string: hello The Hamming distance between these two strings is 4.Explanation / Answer
problem 22: answer
#include<stdio.h>
#include<conio.h>
void main()
{
char str[50];
int vowels = 0, i = 0;
clrscr();
printf(" --------------------------------------------------------");
printf(" PROGRAM TO COUNT THE NUMBER OF VOWELS IN A GIVEN STRING");
printf(" --------------------------------------------------------");
printf(" ENTER A STRING...: ");
gets(str);
while(str[i] != '')
{
if(str[i]=='A'||str[i]=='a'||str[i]=='E'||str[i]=='e'||
str[i]=='I'||str[i]=='i'||str[i]=='O'||str[i]=='o'||
str[i]=='U'||str[i]=='u')
vowels++;
i++;
}
printf(" THE TOTAL NUMBER OF VOWELS IS...: %d", vowels);
printf(" -------------------------------------------------------");
getch();
}
problem 23:
Answer:
Problem: 24: Answer
int hammingDistance(char* str1, char* str2)
{
// If any of the string is null
// or they are not of the same size, then Hamming distance cannot be calculated.
if(str1 == NULL || str2 == NULL || strlen(str1) != strlen(str2))
return -1;
int len = strlen(str1);
int hDistance = 0;
for(int i=0; i<len; i++)
if(str1[i] != str2[i])
hDistance++;
return hDistance;
}
Hamming distance between two strings of equal length is equal to the total number of positions at which corresponding characters in the two strings are different.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.