Copyright © – Sudharsan Iyengar

 

CS – 234.                    Lab 5: Iteration           10/9/24

 

Write an application.

 

a) that requests an integer value from the user and outputs all the integers from 1 to the user entered value and their sum in the end.

 

Ex:                              user inputs 8

 

                              Output should look like

 

                                          1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36

 

b) that requests an integer value (N) from the user and then another value for the width value (W) and outputs all the values from 1 to N – with W values per row – neatly formatted.

 

Ex:                              User inputs 20 for N and 5 for W

 

                              Output should look like:

 

                                1      2     3     4     5

                                6      7     8     9   10

                              11    12   13   14   15

                              16    17   18   19   20

 

c) that repeatedly (one after another) requests integer values from the user until the user inputs a negative number. It should output all those numbers and then outputs the cumulative sum of all the values input by the user (as shown below). It also outputs (in a formatted manner) the smallest and the largest number entered by the user.

 

 

            Ex:                              Use inputs       2 1 5 4 8 6 10 22 5 3 7 5 –5

 

                                                Output should look like:

 

The sum of all the values input is as follows.

 

2 + 1 + 5 + 4 + 8 + 6 + 10 + 22 + 5 + 3 + 7 + 5 = 78

 

The smallest number among the inputs is                     1

The largest number among the inputs is                    22