• 2 days ago
Transcript
00:00Hello everyone, I am going to explain a program of display sum of square of first three odd
00:09numbers.
00:10So we know that the square of first three odd numbers are 1, 9 and 25, when we sum it
00:20and we add these numbers 1, 9 and 25 will get what 35.
00:27So let us understand this program in the flowchart, I have taken variables od for the odd number,
00:34i to count the odd numbers, sq for the square of number and s to get the sum.
00:44I have initialized the values, I have initialized the value of od that is 1, I have initialized
00:49the value of i that is 1 and value of s that is 0.
00:56Now I need the sum of first three odd numbers, that's why this loop is going to carry on
01:01for three times, let us do the dry run, the value inside i is 1, 1 less than 3, yes the
01:08condition is true, it will come to the yes part, what is inside od, it is 1, so 1 into
01:151, so 1 is going to store inside s, in s it is 0, 1 is added to it, so 0 plus 1, new value
01:23inside s it is 1, then what is inside od, it is 1, 2 is going to add with it, so the
01:31new value of od it will be what 3.
01:35I have to carry on the loop, so i equal to i plus 1, so 1 plus 1 that is what 2, so now
01:41inside od it is 3 and inside i it is 2, so now the loop will carry on, 2 less than 3,
01:48the condition is true, now what is inside od, it is 3, what 3 into 3, 9 is going to
01:55store inside sq, inside sum the value is what 1, inside s it is 1, 9 is going to add with
02:04it, so 1 plus 9 that is now inside s it is what 10, then 3 plus 2 that is what 5 and
02:15here it will be what 2 plus 1, 3, again the loop will carry on, 3 equal to 3 the condition
02:22is true.
02:23Now 5 into 5 that is 25, so 25 is going to store inside sq, now what is equation, what
02:31is the value inside s, it is now 10, 10 plus 25 as the value inside sq is what 25, 10 plus
02:4125 inside s it is now 35.
02:46Now I will come to this equation 5 plus 2, 7 and here 3 plus 1, 4 the loop will carry
02:54on, 4 less than 3 the condition is false, so once the loop will complete, once the loop
03:00will complete and when it get terminated after that we have to display the resulted value,
03:07so what is inside s, it is 35, the resulted value is what 35, that is going to print and
03:17then what is stop, so I hope you understand, I am going to implement the program in C in
03:24my next video.

Recommended