Learn Programming Technique C to Master Skills - Fourth Program of Loop ( For Loop )

  • 2 days ago
Transcript
00:00Hi, I'm Sandeep. I'm going to make the program of display of odd numbers user
00:09choice with the help of for loop. Okay, let us see how to make it. I will open
00:22an empty file and then I'll go to file and save file to save it, prg user for
00:36then I will start making the program that is hash include, hash study io.h
00:43standard input output file I have included then int main, inside it I will
00:50take what int od for the odd number and for the number of times the loop is
00:58going to carry on and then what i and od I have given the value 1 okay and here I
01:06will give a message first of all that is what input term that how many times you
01:13are going to carry on the loop okay. I will use what is scanf inside it
01:20%d,&% or you can say and n so the loop is going to carry on to the
01:29value which we give inside the n okay. I will use the for loop for i equals to 1
01:36i is going to compared with n then what i plus plus like this. First thing printf
01:47what I will display the odd number okay slash n odd number is %d,&%
02:00inside od and what od equals to od plus 2 okay and I will use what return 0
02:10statement okay. Now click on the build it's showing me the error why I haven't
02:19used here semicolon at the end so I will use it again save the program by using
02:25ctrl s click on build and now it's showing what 0 error okay. So this is the
02:32program friends let us run and see let me give the term suppose to so only is
02:41going to work for two times so it will display the first two odd numbers 1 and
02:463. If I again run it and if I give here 5 so it's going to display 5 odd
02:54numbers that is 1 3 5 7 and 9. So quickly understand it I have taken 3
03:01variables od n and i the value of od that is what 1 okay. I will put the term
03:09suppose I will put 2 so how many times this loop is going to work for 2 times
03:14the value of i is 1, 1 less than 2 as the value inside n is 2 so the first odd
03:21number is going to work okay to print okay that is what 1 and 1 plus 2 it is
03:283 inside od it is what 3 it will come to the increment part now the value of i
03:34will be what from 1 to what 2 it will come to the decision part 2 equal to 2
03:40yes the condition is true what is the next value inside the od it is 3 so it's
03:47going to print what 3 then 3 plus 2 5 inside od okay new value inside od it is
03:55what 5 it will come to the increment part of i or the new value of i is what
04:003, 3 less than 2 as the value inside n is 2 so 3 less than 2 the condition
04:07will get false this loop will terminate okay and we'll get the two odd numbers
04:13that is 1 and 3 so the value which we are inputting inside n that much time
04:21this for loop is going to work okay and we'll get the odd numbers

Recommended