Question: Public int sumOfN ( int n ) / / Precondition: n is > 0 { int total = 0 ; for ( int temp =

Public int sumOfN (int n)
//Precondition: n is >0
{
int total =0;
for (int temp =1; temp <= n; temp++)
total = total + temp;
return total;
}
The method sumOfNreturns the sum of the integers between 1 and n.
a) What is its order of growth?
b)Create a new method that performs the same function with a lower order of growth. Write the order of growth of your new method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!