Posts

Program to print 2 3 4 5 6, 4 5 6 7 , 6 7 8 , 8 9 , 10 [Nested for loop]

Image
Output Explanation Here, nested for loops is used. The varriable  i initialize from 1 and then passes through next loop j and it gets continue to execute the statement that is inside the j block until the condition of j loop gets false. In the first loop of j, the value of i is 1 which is equal to the initialization of j and prints  the addition of  i and j  i.e  2.  Next time, the value of j increase to 2 but the value of i remains same as 1 and prints the addition of i and j i.e, 3  and  at last loop of j the value of j reaches to 5 but still the value of i is 1 and prints the addition of i and j,  i.e, 6.  When the condition gets false,  steps goes outside the loop and it meets the statement that prints next line.  Since,  the  condition of   loop   of  first loop of i is not false, the loops  begins  agai.  This  time the value of i is 2 and passes inside th...

Program to print odd numbers less than 20 using for loop.

Image
Explanation, Here, i is initialized with value and in every loop, value in i increase by 2 until the condition gets false. Output Exercise: Print even number less than 30 using for loop.

Program to print multiplication table of given number

Image
Explanation In this program, n stores a number and i is an increment. The loop start from 1 and ends on 10. Inside printf, the format %dx%d=%d, here %d are replaced by the value of n which is constant, i that is incremented in every loop and n*i which yields product of n and i. Here, x remain same till the program that makes a multiple sense in the output.

Program to print sum of first ten natural numbers

Image
Explanation Here the variable s denotes to sum and is initialized with value 0. When the loop begins, the s adds the value of i with its previous values along with the loop.When the loop terminate, the last sum is stored in s and is printed outside of the loop. Output

Program to print 'n' numbers using for loop

Image
Explanation Here, in the program, two variables are used n and i . n stores number inputted by user and "i" is used as loop. As the loop increment it will print the value of i until it becomes greater than number stored in n . Output Exercise Make a program that will print "*" for n times using for loop.

Program to print first 9 natural numbers using For loop

Image
Here, I have used Dev C++ platform, it is easy to download. In this program, integer "i" is declared. For Loop has been used initiating i from 1 and print the value of i in each loop increasing value of i by 1 until given condition becomes false ie, i<10. Output Exercise Print natural numbers from 10 to 30 using For Loop. Give your answer in comment section.

Goto Statement or Jump statement in C

Image
T he goto statement is also known as jump statement that makes a program procedure to jump any where from anywhere within the program. It is sometime also called unconditional jump statement.  In this program, it takes name of a person and then prints it. Here " jump: " is a label that goto statement will transfer the step when encountered. So, after printing the name, it asks to continue and if a user enter y or Y the goto statement transfer the step to that label and if any other key is pressed the program will print Visit Again.