Program to Print Numbers Upto N – Control Statements – C Programming Language

Program to Print Numbers Upto N – Control Statements – C Programming Language

Hello friends let’s look at programs which are going to be used or implemented by a follow will not start with a high end program which is actually implemented for a real of obligation let’s start with some simple programs as you proceed in this particular section will increase the level of difficulty for the program’s the very first program is going to be a simple program to print all the numbers up to n and then we will try to modify some aspects of this particular code itself now what I mean by this particular title programmed to print all the numbers up to n suppose if the user says that he had a he will enter the number of value of n as say 25 it means that I am super sprint all the numbers up to 25 I am super sprint 1 2 3 and so on till 25 so whatever the value which the user enters we are supposed to generate all the numbers of those particular n modify the same code for the second option where the user will enter a value of say 25 but rather than printing every value up to 25 or illness I’ll try to print numbers only which are even two four six eight and so on till 24 because the first even number is a 2 from 1 to N and the last number is n minus 1 if n is going to be an order value and if n is going to be an even value and rats were printed we will further modify the same code if the user enters of Rs 25 I wish to print only the order numbers which are in this particular 25 1 3 5 7 and so on till 25 she will write a program for three different cases the first case where I’ll ask the user to enter the value of n and I will print all the numbers from one player and then I’ll ask the user to imprint only even values if the user says that he has sprint only order values up to n have exactly program espada so basically what i need to do is since i said that i am supposed to start with a valuable as one that is my initial value and i know the final value there is a so when you are aware of the initial value that is one and the final there’s n what you need to do is you need to start a traversing from one to n depend upon the application if the user says that you have to print all the numbers from more then then take this I from one and keep on incrementing it till 25 x one stone if the user says that he wants to print only the evil number from 1 to 25 so to identify would the first even number what is the first super number 495 to set to that of the initial value so too is my initial value and then keep on moving towards 25 not in steps of 1 but in steps of two because after to unmask super generator 3am so we generate directly for so one of us from 2 i’ll make this particular loop variable to move to 4 and print the value of this particular for on the screen after printing the value of I that is for I’ll make this particular I to reach 26 print the value of I and so on and so on and so on till I reach 25 if you say then I’m supposed to print all odd numbers from 1 to 25 or want to n in general so it’s that I as one but rather than taking this particular I in steps of 1 are take again in steps of to where I will move from one to n in steps of two to generate only odd numbers so basically a loop variable I has to be used and either had to move from 1 to N or I have to move from 2 to n or add to move from one pair in steps of two or inception depend over the pollution now let us look at the code after understanding the logic of this particular program the program which is used to print all the N numbers on the screen so now if you observe this particular code I will ask the user to enter the value of n read that a value as n so declare two variables n and I where n is the one which is entered by the user of the final value and I is a loop variable at this place now observe the implementation of the for loop in this particular word so I is one in this case check whether one is less than equal to n if true then it says a print to the value of I which is supposed to be used so I am now using a printf as a repetition instruction so printf keeps on reading these instructions again not again till our reaches I reaches the value of n and every time when I goes back I will be one so i will be one in this particular case so i have these four loop examples now if i if i set the value of n s phi so i will be 11 less than equal to fight through print the value of I that is one after slashing says get the cursor next clan go back to i plus plus i plus plus a pre or post will not make any difference absolutely this in the previous video so i plus plus plus plus I so I easy now to to less than equal to five true again print the value of i go back i plus plus i will become 33 lessening prefer to print for for less negative 5 print file file and then you preferred through print now when you go back I becomes 66 less need to verify false false quit you will exhibit the remaining code of this particular part now what if this particular code has to generate only even numbers from 1 to n only even numbers want to end the first you can number which i counted was too so let us write this particular follow for I equals 2 now the first even number that is too and the condition still remain same I less than equal to n but here your I should not move sequentially I has to move by two steps so that it will move to the next few a number that is i equal to i plus 2 and then within this i can have the same instruction that is printf person HD comma so here your eye is printed as the first value to and when it goes back to III the for loop third expression it says I could I plus 2 which means that the value of R is a now increased to four again take the condition if four is less than good and print that for go back and say I could I crystal so when I say I could I plus 2 I will now be increased to six so here I am NOT making this particular I to move sequentially I has been taken from two to six in steps of two what if I have asked you to print all only odd numbers from out there so I’ll further modify the speedy so here the first odd number is I goes to one yes now I have to take this particular I till less than equals to n but in this case also I has to incremented it twice because I should be used for 1357 so again the same printf can be used in this particular for repulsor subsided a for loop which will help us to print all the numbers want n to print only even numbers from tube n or to print only odd numbers from one to whenever you are supposed to move a specific sequence identify by how many steps it is supposed to increment it if it is continuous sequentially then plus plus if it is in steps of two in steps of three inception forth then in that case I cuz 2i plus two so here we can print all the numbers from 1 to N or even numbers odd numbers depend upon the program you can change this particular printf suppose if on need a title printf even numbers are printed f odd numbers are so i can place that particular printf baba this particular for know the very first program introduces the simple application of this particular for loop where i have used to follow for printing purpose thank you

One thought on “Program to Print Numbers Upto N – Control Statements – C Programming Language

  • February 15, 2019 at 12:15 pm

    Hello Friends,
    Watch Complete Video Series of Subject Structured Programming Approach in C Programming only on Ekeeda Application.
    Use Coupon Code "FIRSTTIME" and access any one Subject for Complete one month free.
    Download Ekeeda Application and take advantage of this offer.


Leave a Reply

Your email address will not be published. Required fields are marked *