Solution: Nested Loop with Multiplication (Basic)
This review provides a detailed analysis of how to solve the nested loop with a multiplication problem.
We'll cover the following...
We'll cover the following...
Given Code #
Time Complexity
The outer loop in this problem, i.e., everything under line 9 while (var < n) runs times since var will first be equal to , then , then , then , until it is such that . This means that the outer loop runs a total of times.
Now, let’s have a look at the inner loop for(int j = 1; j < n; j += 2). int j = 1; runs times, j<n executed times and j += 2 executed times. sum++; also runs a total of ...