Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Double summation write two nested for loops to calculate the following double su

ID: 3787211 • Letter: D

Question

Double summation write two nested for loops to calculate the following double summation: Ex: lfs is 3 and t is 2, then summationResult is 18. Your Solution Save C Reset m MATLAB Documentation l function summationResult Double Sum(s t) 2 s: First summation limit (i l to s) 3 t: second summation limit 1 to t) summation Result e; Write two nested for loops to calculate the double summa tion 8 summationResult summationResult i j) 10 end Run Your Solution Code to call your function when you click Run C Reset 1 DoubleSum (3, 2)

Explanation / Answer

for(int i=1;i<s;i++)
{
   for(int j=1;j<t;j++)
   {
       summationResult=SummationResult + (i*j);
   }
}

Execution goes as follows,

with the outer loop as 1, the inner loop runs till t. once till t has completed its loop, the outer loop is incremented and again the inner loop starts its execution.

Assessment test 1:

1x1 + 1x2 + 2x1 +2x2+3x1+3x2 = 18 yes the condition gets satisfied.

Assessment test 2:

no, the return won't be one since the loop does not get executed because the condition is (i<1) ie 1<1

if we have the loop as i<=1 and j<=1 then both the loop is executed and the Answer will return 1

Assessment test3:

The return will be 89, How?

the outer loop executes from 1 to3 and not 4 since I<4 and not i<=4;

the inner loop executes till 4 and not 5 since j<5 and not j<=5

for every outer loop incremented by 1 the inner loop executes from j=0to4

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote