 Hello everyone welcome to this video lecture series on problem solving. In this particular lecture I will be discussing a problem and we shall see how to solve this particular problem using loop constructs in C. Now the entire objective of this video series is to solve problems and to prepare yourself for competitive programming. So we see in competitive programming that we have a particular problem and in this video series we shall see to solve a particular problem using the different constructs and in this video we will see how to solve it using loops in C. So at the end of this session you will be able to solve a problem by writing a C program using loops and if condition. So you are encouraged to refer to the following videos before you try to solve the problem if you are unaware or if you are very new in using for loops and nested loops you can refer to these video lectures which are already available in the playlist that is available at the right side of the video that you are watching and then you may continue to solve this problem. So the problem statement that we will be discussing today is consider you are given a string of random N characters in English language write an efficient C program to find the number of vowels in the string. Now in English alphabets we know that the characters A, E, I and O, U are known as vowels and rest 21 alphabets are known as consonants. So we want to write a program that in a given string of random characters we want to count how many vowels are present in the string say for example the input string is America. Now America has four plus three that is seven characters and out of these seven characters four are vowels. A is a vowel, E is a vowel, I and A again are vowels. So the total count of vowels in this string is four. Now we shall see at the algorithm the process how we need to go about solving the problem. First we initialize our problem solving then we take the input string from the user and to process this input string we need to store it in some variable here I will name the variable as S, S, T, R. So the entire string is stored in S, T, R. Now if I want to count the number of vowels I will need a counter variable. So I initialize a variable to store the count of vowels and I initialize it to zero name it as vowel. Now to process this string I need to scan the string from start till the end of the string and whenever I detect a vowel I will increment the count of vowel by one if the current character is detected as a vowel and once I reach to the end of the string once I reach to the end of the string I will display the count of vowel. If you have understood the algorithm we can go ahead and solve the problem. Now I will demonstrate how we will go about solving the problem. So this is code blocks IDE. I highly recommend you to use this IDE because this is a freely available software and it helps to keep all your code compiled and in one place so that you can build the entire project at the same time. So this is the program to find the number of vowels in a string. I have included these header files which I am going to use in my program. Int max size equals 100 that is the input string can have maximum of 100 characters integer I length and vowel have been declared here. I have declared an extra variable consonant which I am going to not use now but later if there is need we will be using it. This is the step one of the algorithm. We start step one at line number 14. So the user is prompted to enter string and we are using F get S method to take the input from the. Now we come to the second step of the algorithm. Here we initialize the variable vowel as zero and I want to scan the string from zero that is the start of the string till the end of the string. Now the end of the string will be stored in LEN that is the length of the string. So STR LEN is an inbuilt function in string.h which helps us to find the length of the string. Now we come down at line number 34 to implement the third step of the algorithm. Now I am scanning this string from zero to length. Now if is alpha string of I not equals zero. Now I will give the explanation that why we are using is alpha function. Is alpha function when passed a character is a function to check if the past character is an alphabet or not. So we want to only check for alphabets. We don't want any special symbols. We don't want any brackets or full stop in the string. We just want to see whether it is a vowel or not. So if the particular character in string of I if it is not equal to zero what this means is this function returns a non zero value if the alphabet is detected. That means if STR of I is an alphabet it will return a non zero integer. Now if this if condition returns a non zero integer that means that the current character is an alphabet we compare if it is A E I O U in the small letters or A E I O U in the capital letters. If any of these 10 characters that is capital vowels or small vowels are detected we increment vowel by one. And then the last step is total number of vowels printed is stored in vowel and we display vowel. I shall execute this program and we shall see the output. I take a small string hello world. So the total number of vowels in this string is 3 where E O and O are vowels. So since we have used F get S function it is also including the spaces in the string. And since we have used is alpha function and it is not including any of the special symbols that we have considered here. So this is the entire program to detect the vowels in the given string. This code is available in the description section below. You can see the code and try to run it for yourself on your PC. So at this point in time I want you to pause the video and change the program to find both the number of vowels as well as consonants in the given program. Pause the video write the program for yourself and we will come back and discuss the solution. So here is the solution of the program that I had asked you to write. I have declared one as I mentioned earlier I had declared a variable consonant which will store the consonants that is the remaining 21 characters which are different than the vowels in the English alphabet. And we take the input and also as we take the input here in line number 14 and 15 we scan the entire array of characters in this particular condition if condition. Now if the character that is scanned if it is A E I O U the vowel will be incremented and if it is any of the 21 characters which are different from A E I O U the consonant variable will be incremented. And any other variable or any other character like spaces like commas like exclamation marks will be excluded because we are using is alpha function. And at the end I am printing the total number of consonants which are stored here. Now I am going to execute this program and we shall see the output for the written changes. Hello world is my string with an exclamation mark. So the total number of vowels as seen earlier remains same that is 3 and the total number of consonants in the string is H L L that is 3 and W R L D that is 4 which makes it to be 7. So we come to know that exclamation mark has been excluded because that is neither a vowel or a consonant. So you can take the help of this program and try to find out the number of vowels and consonants that appear in a string. So we go back to our presentation. So these are the references that I have referred to you may also refer this for further explanation of the functions and the procedure to solve this problem. Thank you.