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



WhileLoop Program


Description

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

Associated Concepts:

while loop

Algorithm:

Input a positive integer n

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

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

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

Source Code



Sample Run



Video