Category
š
LearningTranscript
00:00Hello everyone, I am Sandeep Thakur.
00:06Now today I am going to start loop with if statement.
00:10Earlier what we have studied, we have studied if statement separately and we have studied
00:17loop separately.
00:18Now I am going to combine both the things loop and if statement.
00:24So how are the programs of loop with statement that I am going to explain.
00:29Let us first understand in the flowchart then I am going to implement in C.
00:35So this is the program friends, input numbers from keyboard and count total even numbers
00:41and total odd numbers.
00:44So this is also a user choice program as I haven't mentioned that how many numbers I
00:48have to input from the keyboard.
00:51The numbers of which I am going to input those numbers can be odd or can be even.
00:59For that we have to check.
01:02Now how many numbers we have to input for that we have to apply loop and for checking
01:08also we have to input a particular number, is it odd or is it even.
01:15For that I have taken the variables, how many times the loop will carry on for that I have
01:20taken the variable n, which number we have to input I have taken for that num to see
01:27is it odd or even for that ev and odd.
01:31So we have to count the total odd numbers and total even numbers for the counting of
01:36even numbers I have taken ev for counting of odd numbers I have taken odd and to carry
01:41on loop I have taken the counter variable i.
01:46I have defined the values or I can say I have initialized the value of ev that is what 0
01:51of od 0 and i equals to 1.
01:56Now I am going to input the term or you can say the value of n, I input the value of n3
02:04so how many times this loop is going to carry on, this loop is going to carry on for 3 times.
02:11This outer decision box represents to the loop and this one represents to the if statement.
02:22So what is value of i, it is 1, 1 less than 3, yes 1 less than 3 the condition is true
02:28it will come to the yes part.
02:30I am going to input the first number, suppose I input what 60.
02:35So it is going to check 60, I have used the module operator module by 2 and it will divide
02:44if it is going to give the remainder what 0 that's mean it is what even number and
02:53it is going to count.
02:54So 0 plus 1 that is equal to 1 and it is going to also count the counter variable as we have
03:02to carry on the loop so 1 plus 1 that is what 2.
03:05So the value of i is what 2, so the loop will carry on 2 less than 3 the condition is true
03:13the next number which I am going to input that is what 5.
03:19Again I will module it by 2 so obviously it is going to give the remainder so this condition
03:26will get false it will come to the no part it is going to count that 5 is the odd number
03:32so that is what 0 plus 1 equals to 1 so it is counted the odd number.
03:40We have input two numbers from that is 60 and 5 it counted the first number is what
03:45even and the second number 5 is what odd and if you see it is also connected with the counter
03:51variable so 2 plus 1 now the value of i is what 3.
03:55So the value of i is 3, 3 equal to 3 the condition is true.
04:01The next value is going to input that is what 10, 10 is moduled by 2 obviously the remainder
04:06will be what 0 so 0 equal to 0 so it is even number so it will come to the yes part.
04:14What is the value of ev it is 1, 1 is going to add so it is what 2.
04:20So it is count the odd number the even number it is counted the even number then it is connected
04:27with the counter variable so what is the value of i it is 3, 3 plus 1 4 again it is going
04:34to this loop 4 less than 3 now the condition get false so it is going to print the number
04:42of even numbers and the odd numbers.
04:47So it printed that even number is 2 and the odd number is 1.
04:52Thanks for watching this video in the next video I am going to make the program.