COMP2243 - Programming and Problem Solving

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Repetitions/Loops WhileLoop.java LoopWithCounter.java LoopWithSentinel.java LoopWithFlag.java SimpleInterest.java Factorial.java Fibnonacci.java PrimeNumber.java GCD.java PopulationGrowth.java ForLoop.java DoWhileLoop.java FileIO_Tickets.java FileIO_Salary.java NestedLoop.java



ForLoop Program


Description

This program uses several for loops to print a sequence of numbers and calculates the sum and average of these numbers.

Associated Concepts:

for loop

Algorithm:

Input a positive integer n

Use a for loop to print every number from n to 50,
and calculate the sum and average of these numbers

Use another for loop to print every number from 50 to n,
and calculate the sum and average of these numbers

Use another for loop print every even number from n to 50,
and calculate the sum and average of these numbers

Source Code



Sample Run

The sample run is the same as WhileLoop program.



Video