Computer Science, asked by tusharraj77123, 18 days ago

WAP to enter any string . Make a new string of viwels and consonant and also find the number of vowels and consonant. Display the requried string .

(C++)

No spam ;
Right answers are appreciated. ​

Answers

Answered by manu9035
1

Answer:

#include <stdio.h>

int main() {

char line[150];

int vowels, consonant, digit, space;

// initialize all variables to 0

vowels = consonant = digit = space = 0;

// get full line of string input

printf("Enter a line of string: ");

fgets(line, sizeof(line), stdin);

// loop through each character of the string

for (int i = 0; line[i] != '\0'; ++i) {

// convert character to lowercase

line[i] = tolower(line[i]);

// check if the character is a vowel

if (line[i] == 'a' || line[i] == 'e' || line[i] == 'i' ||

line[i] == 'o' || line[i] == 'u') {

// increment value of vowels by 1

++vowels;

}

// if it is not a vowel and if it is an alphabet, it is a consonant

else if ((line[i] >= 'a' && line[i] <= 'z')) {

++consonant;

}

// check if the character is a digit

else if (line[i] >= '0' && line[i] <= '9') {

++digit;

}

// check if the character is an empty space

else if (line[i] == ' ') {

++space;

}

}

printf("Vowels: %d", vowels);

printf("\nConsonants: %d", consonant);

printf("\nDigits: %d", digit);

printf("\nWhite spaces: %d", space);

return 0;

}

Explanation:

Enter a line of string: C++ 20 is the latest version of C++ yet.

Vowels: 9

Consonants: 16

Digits: 2

White spaces: 8

Similar questions