for Statement (Sample Program)

Sunday, July 29, 2012
Let’s write a program using for loop to find the sum of the squares of the integers from 1 to n. Where n is a positive value entered by the user (i.e. Sum = 12 + 22 + 32 + ……+ n2) The code of the program is given below: In the program we declared three variables i, n and sum. We prompted the user...

Increment Decrement Operators

We have seen that in while, do-while and for loop we write a statement to increase the value of a variable. For example, we used the statements like counter = counter + 1; which adds 1 to the variable counter. This increment statement is so common that it is used almost in every repetition structure...

for Statement (Sample Program)

Saturday, July 28, 2012
Let’s take an example to explain for loop. We want to write a program that prints the table of 2 on the screen. In this program, we declare a variable counter of type int. We use this variable to multiply it by 2 with values 1 to 10. For writing the table of 2, we multiply 2 by 1, 2, 3 .. upto 10 respectively...

for Statement

Let’s see what we do in a loop. In a loop, we initialize variable(s) at first. Then we set a condition for the continuation/termination of the loop. To meet the condition to terminate the loop, we affect the condition in the body of the loop. If there is a variable in the condition, the value of that...

Use of Operators

Sunday, July 1, 2012
Here are sample programs which will further explain the use of operators in programming. Problem Statement: Write a program that takes a four digits integer from user and shows the digits on the screen separately i.e. if user enters 7531, it displays 1,3,5,7 separately. Solution: Let’s first analyze...
 

introduction to programming Copyright © 2011-2012 | Powered by Blogger