Posts

Showing posts from April, 2020

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.