Question

In: Computer Science

how can you count the number of different letters there are in a word in C...

how can you count the number of different letters there are in a word in C programming?

Solutions

Expert Solution

Create array of size 52 . if letter is lower case increate at first 26 position like a at 0,b at 1. Silipar to that,if letter is uppercase increament from 26,like A at26,B at 27...

Code

#include<stdio.h>

int main()
{
    char c[]="samplecheck"; //sample string
    int s[52];
    for(int i=0;i<52;i++) //set all elements to 0
        s[i]=0;
    for(int i=0;i<strlen(c);i++)
    {
        if(islower(c[i])) //if lower increase from position 0-25
        {
            s[(int)c[i]-97]++;
        }
        if(isupper(c[i])) //if upper increase from position 26-51
        {
            s[(int)c[i]-39]++;
        }
    }
    int tot=0;
    for(int i=0;i<52;i++)
    {
        if(s[i]!=0) // if not zero the letter is presented in the word
            tot+=1;
    }
    printf("there is %d different letters in the word %s",tot,c);
    return 0;
}

Terminal Work

.


Related Solutions

7. How many different ways can the letters in “COUNT” be arranged? 8. How many different...
7. How many different ways can the letters in “COUNT” be arranged? 8. How many different ways can the letters in “PROBABILITY” be arranged? 9. A pizza restaurant offers 15 different toppings, but only allows customers to select up to four different toppings for each pizza. How many different ways are there for customers to choose up to four toppings for a pizza? 10. A youth soccer team consists of 12 players. When they have games, they play simultaneously on...
A machine prints a word and the number of letters in this word is a Poisson...
A machine prints a word and the number of letters in this word is a Poisson distributed random variable with parameter λ (so it could possibly have zero letters). However, each letter in the word is printed incorrectly with probability 2/3 independently of all other letters. Compute the expectation and the variance of the number of incorrect letters in the word that the machine prints.
1) Find the number of unique ways that the letters in the word can be arranged:...
1) Find the number of unique ways that the letters in the word can be arranged: KERFUFFLE 2) A survey of commuters found that 313 owned a motorcycle, 232 owned a car, 269 owned a moped, 98 owned a car and a moped, 57 owned only a car, 104 owned a motorcycle and moped but not a car, 69 owned all three, and 64 owned none. What proportion of people surveyed owned only a moped? Leave your answer as an...
How many ways can you arrange the letters of the word “COURSE” if: The first and...
How many ways can you arrange the letters of the word “COURSE” if: The first and last letters must be a vowel.
a) How many ways can the letters of the word COMPUTER be arranged in a row?...
a) How many ways can the letters of the word COMPUTER be arranged in a row? b) How many ways can the letters of the word COMPUTER be arranged in a row if O and M must remain next to each other as either OM or MO? c) How many permutations of the letters COMPUTER contain P, U and T (all three of them) not to be together in any order?
In C Exercise 8.1 A word is said to be “abecedarian” if the letters in the...
In C Exercise 8.1 A word is said to be “abecedarian” if the letters in the word appear in alphabetical order. For example, the following are all 6-letter English abecedarian words. abdest, acknow, acorsy, adempt, adipsy, agnosy, be?st, behint, beknow, bijoux, biopsy, cestuy, chintz, de?ux, dehors, dehort, deinos, diluvy, dimpsy a. Describe an algorithm for checking whether a given word (String) is abecedarian, assuming that the word contains only lower-case letters. Your algorithm can be iterative or recursive. b. Implement...
55) A) In how many dierent ways can the letters of the word 'JUDGE' be arranged...
55) A) In how many dierent ways can the letters of the word 'JUDGE' be arranged such that the vowels always come together? B) How many 3 digit numbers can be formed from the digits 2, 3, 5, 6, 7 and 9 which are divisible by 5 and none of the digits is repeated? C) In how many ways can 10 engineers and 4 doctors be seated at a round table without any restriction? D) In how many ways can...
Question # 4. (a) Determine the number of ways to rearrange the letters in the word...
Question # 4. (a) Determine the number of ways to rearrange the letters in the word QUESTION. (b) Determine the number of ways to rearrange the letters in the word BOOKKEEPERS. (c) Determine the number of ways to rearrange the letters in the word SUCCESSFULLY, assuming that all the Ss are kept together, and the E and F are not side-by-side
In C++ For this assignment, you will write a program to count the number of times...
In C++ For this assignment, you will write a program to count the number of times the words in an input text file occur. The WordCount Structure Define a C++ struct called WordCount that contains the following data members: An array of 31 characters named word An integer named count Functions Write the following functions: int main(int argc, char* argv[]) This function should declare an array of 200 WordCount objects and an integer numWords to track the number of array...
In how many ways can you rearrange the letters A, B, C, D, E?
In how many ways can you rearrange the letters A, B, C, D, E?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT