• 2 months ago
Transcript
00:00Hello everyone, today I am going to make the sum of square of first three odd numbers in
00:08C. I am going to make the program in C, just watch. I am going to open a new file and I
00:24will save it also, prgsq something, I have given the name to it and save it. First thing
00:37what I will do, I will use what hash include, hash tdio.h and I will use int main. Now let
00:48us think about the variables int, first of all od for the odd number, sq to get the square of it,
00:56s for the sum and i to carry on the loop and I will initialize the value, od equals to 1,
01:04s equals to 0. I will apply the loop, i equals to 1, how many times the loop is going to work,
01:17so i less than equal to 3 and then what i++. Inside here first thing I will do,
01:26write down the equation to get the square of odd number. Then I need to do the sum,
01:34so s equals to s plus sq and then I have to increment the odd, so od equals to od plus 2.
01:43When the loop will terminate then only I will use what slash n sum of square of first three
02:07odd numbers, that is what percent d and where it is, it is inside s. Let us save it and run it,
02:31let me click on build, so it is showing zero errors and let us run it, so it should show
02:39the sum of square of first three odd numbers 35, so it is showing correct result.
02:46To clearly understand it, I have taken od, sq, s and i variables, I have initialized the value of
02:55od, it is 1, I have initialized the value of s, that is what 0, the value of i, it is 1,
03:01it will come to the decision part, 1 less than 3, the condition is true. What is inside od,
03:07it is 1, so 1 into 1, so the value inside sq will be 1. Inside s, the value is what 0,
03:16inside sq it is 1, so 0 plus 1 is 1, so now inside s it is 1 and 1 plus 2, it is 3,
03:25the loop will carry on, the value of i is going to increment by 1, that is 2, 2 less than 3,
03:32the condition is true. What is inside od, it is 3, so 3 into 3, 9, so new value inside sq is 9.
03:41Inside s, it was 1, so 1 and what is now inside sq, it is 9, so 1 plus 9,
03:50now new value inside s is 10, please remember that inside s, now it is 10,
03:56then 3 plus 2, it is 5, so new value inside od is what 5, value of i is going to increment by 1,
04:04so now from 2, it is what 3, 3 equals to 3, the condition is true. What is inside od, it is 5,
04:11so 5 into 5, 25, inside sq, it is 25. What was inside s, it is 10, it was 10, inside sq, it is
04:2325, so 10 plus 25, new value inside s is 35 and what 5 plus 2, 7, i is going to increment by 1,
04:35that is from 3 to what 4, 4 less than 3, condition will get false, this loop will terminate,
04:44the for loop is going to terminate and what was the last value or what is the last value inside
04:50s, it is 35, that is going to display after the termination of the loop,
04:55sum of square of first three odd numbers, 35.

Recommended