Write a fortran program to read a string and count the vowels (“a”, “e”, “i”, “o
ID: 3678205 • Letter: W
Question
Write a fortran program to read a string and count the vowels (“a”, “e”, “i”, “o”, and “u”). The program should provide a count for each vowel and a total count of vowels. The program should ensure that the vowels are counted for both upper and lower-case. Test the program on a series of different input values and verify that the output is correct for those input values.
Assume the input string may be no longer than 1000 characters.
Output shall be a formatted list of the format:
X occurs YYY times.
where X is each of the vowels and YYY is the number of occurrences in the input string.
Explanation / Answer
program vowelchecker
implicit none
!finding no of vowels in a sentence.
integer : : vowels=0
integer : : blank=0, other=0,i
character : : letter
character (len=1000) :: line
read '(a)', line
do i=1,1000
!extracts one character at position of i
letter= line(i:i)
select case(letter)
case ('A' ,'E','I','O','U','a','e','i','o','u')
vowels=vowels + 1
case(' ')
blank=blank+1
case default
other=other+1
end select
end do
print *,'Vowels=' vowels
print *,'Blanks=' blank
end program vowelchecker
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.