* add comments Problem Statement Write a C program that gets a set of characters
ID: 3836998 • Letter: #
Question
* add comments Problem Statement Write a C program that gets a set of characters from the user and store it in a char array. The reading continues until two consecutive (##)characters are detected. You may use the following declaration for your array: char chars[50]: If the array is not empty, then the program displays the following about the elements of the array: 1. The number of vowel characters. 2. The number of non-vowel characters. 3. The number of lower case letters. 4. The number of upper case letters. 5. The percentage of upper case letters of all letters. 6. The percentage of vowels of all characters. 7. The number of numerical characters. 8. The number of prime numbers. 9. All prime numbers in the input set. Notes Note 1: iftwo characters are entered at the begging of the input, the program will stop as shown in Fig.1. In this case, the array would be empty. Enter A Set of Characters: Unfortunately, the array is empty! The program will stop now Fig 1 Note 2: To convert a number character to its corresponding numerical value, subtract the zero character from the character itself, for example (int)( 9 0') 9. Note 3: Make sure to avoid division by zero wherever possible. Note 4: Test your program with the following input sets: a) bcde 12345670 AB## c) d) 1234w##kiExplanation / Answer
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char text[80], ch ;
int vowel = 0, cons = 0, digit = 0, word = 0, special = 0, i = 0 ,upper = 0, lower = 0;;
clrscr() ;
printf("Enter the text : ") ;
gets(text) ;
while((ch = tolower(text[i++])) != '')
{
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
vowel ;
else if(ch >= 'a' && ch <= 'z')
cons ;
else if(ch >= '0' && ch <= '9')
digit ;
else if(ch == ' ')
word ;
else
special ;
}
while (ch[i] != '') {
if (ch[i] >= 'A' && ch[i] <= 'Z')
upper++;
if (ch[i] >= 'a' && ch[i] <= 'z')
lower++;
i++;
}
word ;
printf(" Enter a Set of characters : ") ;
printf(" 1.Number of vowels = %d", vowel) ;
printf(" 2.Number of non-vowels = %d", cons) ;
printf(" Uppercase Letters : %d", upper);
printf(" Lowercase Letters : %d", lower);
printf(" Number of digits = %d", digit) ;
printf(" Number of special characters = %d", special) ;
printf(" Number of words = %d", word) ;
getch() ;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.