0% found this document useful (0 votes)
3 views

Assignment 3

The document outlines an assignment to calculate the total number of characters and the occurrences of vowels in a given string. It provides an algorithm and a C program code that accepts a string input, counts the characters (excluding newlines), and counts each vowel's occurrences. The output displays the total character count and the counts for each vowel (A, E, I, O, U).

Uploaded by

Nina dobrev
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment 3

The document outlines an assignment to calculate the total number of characters and the occurrences of vowels in a given string. It provides an algorithm and a C program code that accepts a string input, counts the characters (excluding newlines), and counts each vowel's occurrences. The output displays the total character count and the counts for each vowel (A, E, I, O, U).

Uploaded by

Nina dobrev
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment 3

Q.Calculate the total number of characters in the string and the total number of
vowels in the string with
the number of occurrences in the string.

ALGORITHM
1.Input: Accept a string of characters (could contain spaces,
punctuation, and newline characters).
2.Output:
● Total number of characters (excluding newline).
● Count of each vowel (a, e, i, o, u) and their occurrences in
the string.
PROGRAM CODE
#include <stdio.h>

int main() {

char str[100];

int i=0,count = 0;

int A = 0, E = 0, I = 0, O = 0, U = 0;

printf("Enter a string: ");

fgets(str, 100,stdin);

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

count++;

if (str[i] == 'a' || str[i] == 'A') {

A++;

} else if (str[i] == 'e' || str[i] == 'E') {

E++;

} else if (str[i] == 'i' || str[i] == 'I') {

I++;

} else if (str[i] == 'o' || str[i] == 'O') {

O++;

} else if (str[i] == 'u' || str[i] == 'U') {

U++;

}
}

printf("Total number of characters: %d\n", count-1);

printf("A: %d\n", A);

printf("E: %d\n", E);

printf("I: %d\n", I);

printf("O: %d\n", O);

printf("U: %d\n", U);

return 0;

OUTPUT

You might also like