Question

Write a C program that will produce the EXACT output shown below. Write a program to...

Write a C program that will produce the EXACT output shown below.

  1. Write a program to find out the number of words, spaces, vowels, consonants, along with special characters in a sentence. Take the data below as an example.

Your C program should take the data in the arrays and produce the output below, neatly formatted as shown

Enter a sentence: My cat’s name is Bella.

You sentence includes:

            Number of words: 5

            Number of spaces: 4

            Number of vowels: 6

            Number of consonants and special characters: 13

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C CODE

#include<stdio.h>
#define MAX 1000 // DEFINE MAX LENGTH OF CHARACTERS ARRAY

int main()
{
   char str[MAX]; // CHARACTER ARRAY OR STRING TO HOLD THE INPUT STRING
   int i; // INDEX VARIBLE

   // DECLARE ALL COUNT VARIABLES AND INITIALIZE WITH 0

   int words=0;
   int spaces=0;
   int vowel=0;
   int consonant=0;
   int special=0;
   int aplhbate=0;

   // ACCEPT THE STRING FROM USER
   printf("Enter the string : ");
   scanf("%[^\n]",str);


   //ITERATE THE STRING UPTO NULL CHARACTER. '\0' OR NULL IS TERMINATING CHARACTER OF A STRING
   // INSTEAD OF '\0' NULL MAY BE USED DEPEND UPON COMPILER

   for(i=0; str[i]!='\0'; i++)
   {
       // COMPARE EACH CHARACTER FOR SPACE.
       if( str[i]==32)
       {
           spaces++;
       }

       // COMPARE EACH CHARACTER FOR VOWEL , WHETHER UPERR CASE OR LOWER CASE
       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')
       {
           vowel++;
       }

       // COMPARE EACH CHARACTER TO CHECK ALPHABATE
       if( (str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z') )
       {
           aplhbate++;
       }
   }

   // NUMBER OF WORDS WILL BE 1 MORE THAN NO. OF SPACES.
   words=spaces+1;

   // GET NO OF CONSONANT
   consonant= aplhbate- vowel;

   //GET NO OF CPECIAL CHARACTER
   // 'i' IS INDEX VARIABLE FOR THE STRING, NOW IT IS HOLDING THE STRING LENGTH
   // DIRECTLY TOTAL OTHER CHARACTERS(consonants and special) CAN BE ALSO FOUND AS : i - (vowel+spaces)
   special=i- (aplhbate+spaces);

   //PRINT THE COUNTRS
   printf("\n Number of words : %d ", words);
   printf("\n Number of Spaces : %d ", spaces);
   printf("\n Number of Vowels : %d ", vowel);

   printf("\n Number of consonants and special characters: %d ", special+consonant );


   return 0;
} // END OF MAIN

SCREEN SHOT CODE

SCREEN SHOT OUTPUT

Add a comment
Know the answer?
Add Answer to:
Write a C program that will produce the EXACT output shown below. Write a program to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ program by netBeans java language Exercise #2: Write a java program that prompts the user...

    C++ program by netBeans java language Exercise #2: Write a java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, 0, o, I, i) c. the number of characters as numbers or special characters (other than English letters a..z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse:...

  • Exercise #3: write a Java program that prompts the user to enter a sentence. The program...

    Exercise #3: write a Java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, O, o, I, i) c. the number of characters as numbers or special characters (other than English letters a.z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse: UAEU is the university of the...

  • C++, dont use arrays on this problem Problem (5) (10 points) Write a C++ program that...

    C++, dont use arrays on this problem Problem (5) (10 points) Write a C++ program that reads in a sentence and outputs that sentence without vowels and spaces, along with counting how many vowels were removed. You may assume there will be only one period that occurs at the end of the sentence. Also assume that the vowels are always "a", "e", "1", "o" and "u" (not "w" or "y"). All letters will also be input in lower case. Sample...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • please use c++ please write down the input file information please add comments for some codes...

    please use c++ please write down the input file information please add comments for some codes please do not use #include <bits/stdc++.h> we did not learn it yet thank you CSIT 575-Take Home Lab #11: Arrays To learn to code, compile and run a program processing characters. Assignment Plan and code a top-down modular program utilizing ARRAYS to solve the following problem, using at least 3 functions (called from the main() section or from another function) to solve the problem....

  • C++ 1) Write a function named WordCount, which determines the number of words in a “C...

    C++ 1) Write a function named WordCount, which determines the number of words in a “C type” string. The function will have one parameter (the address of the string) and will return the number of words (words are separated by one or more spaces). (15 points) 2) Write a function named VowelConsonant which will have three parameters - all “C type” strings. The function will place all vowels (the characters a, e, i, o, u) from the first string into...

  • 1. Write a C++ program to output a framed greeting. The program will produce five lines...

    1. Write a C++ program to output a framed greeting. The program will produce five lines of output. The first line begins the frame. It is a sequence of * characters as long as the person's name, plus some characters to match the salutation ("Hello, "), plus a space and an * at each end. The line after that will be an appropriate number of spaces with an * at each end. The third line is an *, a space,...

  • Write a program in C plus plus that reads input a word at a time until...

    Write a program in C plus plus that reads input a word at a time until a lone q is entered.The program should then report the number of words that began with vowels, the num- ber that began with consonants,and the number that fit neither of those categories. One approach is to use isalpha() to discriminate between words beginning with letters and those that don’t and then use an if or switch statement to further iden- tify those passing the...

  • write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase...

    write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase letters, digits and punctuations. output the results neatly formatted and labeled in columns.

  • Write a program which gives the user the option to separate, Vowels or Consonant from a...

    Write a program which gives the user the option to separate, Vowels or Consonant from a given text from a file. We will display the separated data on screen and also store it in output file. This is for C++ . Name of the input file to be used is: SeparateConVow.dat . The input file has this sentence: THIS IS THE FINAL PROJECT FOR OUR CLASS . The code should separate the vowels and consonants in that sentence. ^ ....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT