• 2 days ago
Transcript
00:00Hello everyone, I am Sandeep.
00:05In today's video I am going to explain that how to display square of first three odd numbers.
00:14So we know the first three odd numbers are 1, 9 and 25.
00:21For that here I have taken three variables for odd numbers I have taken od, to count
00:28I have taken i, this is the counter variable and to calculate the odd number I have taken
00:34what as q.
00:35I have defined the value of od for the odd number 1 and I have defined the value of i
00:41that is equals to 1.
00:43We need the first three square of odd numbers.
00:48So this loop is going to carry for how many times, for three times.
00:53Now let us do the dry run and understand it.
00:55The value of i it is 1, 1 less than 3 condition is true, it will come to the yes part.
01:02What is inside od it is 1 so 1 into 1, 1 into 1 so the resulted value is going to store
01:10inside as q that is what 1 and it's going to display.
01:15So see we got the first square of odd number but we need other odd numbers also so that
01:23we can do the square of it for that the equation is here that is od equals to od plus 2.
01:31So what is value of od it is 1, 2 is going to add with it so 1 plus 2 it is what 3.
01:36So the new value inside od is what 3, we have to count it also so we have given equation
01:43here i equal to i plus 1.
01:45What is inside i it is 1, 1 is added to it so 1 plus 1 that is what 2.
01:52So just remember the values, the values of od is what 3, the value of i it is what 2.
01:58Now the loop will carry on, 2 less than 3 as the value inside i it is what 2.
02:05So 2 less than 3 condition is true, it will come to the yes part.
02:10What is inside od it is 3 so what 3 into 3 and the resulted value 9 is going to store
02:19inside sq so it's going to print sq that is what 9.
02:25Now again it will come to the equation what is inside od it is 3, 2 is going to add with
02:31it so the new value inside od is what 5.
02:34It will come to the counter variable what is inside i it is 2, what is going to add
02:41with it that is 1 so 2 plus 1 3.
02:45Now the new value inside i is 3 and the new value inside od is what 5.
02:51Again the loop will carry on, it will come here and value of i is 3 so 3 equals to 3
03:00the condition is true, it will come to the yes part and what is inside od it is what
03:065 so 5 into 5, 5 into 5 that is what 25 so it's going to print what 25.
03:15It will come to this equation 5 plus 2 7, it will come to this equation 3 plus 1 4 again
03:24it's going to check the condition 4 less than 3.
03:28Now this time the condition will get false so the loop will terminate it will come to
03:33the no and then stop but we get the result that is 1 9 and 25.
03:41So this is the dry run of the program in the next video I am going to create this program
03:47in C. Thanks.

Recommended