Easy: Solve T(n)=T(n-1)+n by Iteration Method

前端 未结 5 2227
灰色年华
灰色年华 2021-02-19 19:59

Can someone please help me with this ?

Use iteration method to solve it. T(n) = T(n-1) +n

Explanation of steps

5条回答
  •  抹茶落季
    2021-02-19 20:57

    In pseudo code using iteration:

    function T(n) {
        int result = 0;
    
        for (i in 1 ... n) {
           result = result + i;
        }
    
        return result;
    }    
    

提交回复
热议问题