Technology has advanced to the point where programming has become an essential part of our lives. We use software and applications for communication, entertainment, education, and work, and these are all built on programming languages.

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



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.
Share:

Program to print multiplication table of given number


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.



Share:

Program to print sum of first ten natural numbers


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


Share:

Program to print 'n' numbers using for loop


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.
Share:

Translate

Wikipedia

Search results