Exercise Beginner: Product of numbers

Request:
Find the product in a segment of numbers when there is given the beginning of the segment and the ending of the segment.

Solution
This exercise can have different solutions, in this case we will show the one by using the for loop. If you are not familiar with the for loop follow the lesson 7 first. One possible solution of this problem is shown in the example code bellow:

Example code:

As it can be seen is a straightforward solution, where after taking the starting element and ending element from user, we set them as the begining, int i= firstNumber, and ending elements of the loop i<=lastNumber and we multiply every element with the previous product.

The result of the execution is shown in the fiugre 1 bellow.


Figure 1: Execution


(please report broken link in the comment)

Comments

Popular posts from this blog

Free host and domain

C++ Beginner: Lesson 3 - Simple calculator

C++ Beginner: Lesson 4 - Tic Tac Toe game