Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

How many times is the print statement executed, wehre i,j,k ∈ Z? Explain

For i := 1 to 12 do

For j :=5 to 10 do

For k:=15 downto 8 do

Print (i-j)*k

share|improve this question

closed as off-topic by Ivo Terek, muaddib, Strants, Peter Woolfitt, Travis Jul 18 at 22:33

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "This question is missing context or other details: Please improve the question by providing additional context, which ideally includes your thoughts on the problem and any attempts you have made to solve it. This information helps others identify where you have difficulties and helps them write answers appropriate to your experience level." – Ivo Terek, Strants, Travis
  • "This question is not about mathematics, within the scope defined in the help center." – muaddib, Peter Woolfitt
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
OMG! When you don't know what to do, try multiplying... –  jpalecek Oct 10 '12 at 0:27
    
Welcome to math.SE: since you are new, I wanted to let you know a few things about the site. In order to get the best possible answers, it is helpful if you say in what context you encountered the problem, and what your thoughts on it are; this will prevent people from telling you things you already know, and help them give their answers at the right level. If this is homework, please add the homework tag; people will still help, so don't worry. Also, many find the use of imperative ("Prove", "Solve", etc.) to be rude when asking for help; please consider rewriting your post. –  Julian Kuelshammer Oct 16 '12 at 19:34

1 Answer 1

up vote 3 down vote accepted

Start inside and work out. The innermost loop executes once for each value of $k$ from $15$ down to $8$; that’s $15-7=8$ values, so the print statement is executed $8$ times every time the innermost loop is entered.

Now how often is the innermost loop entered? Once for each value of $j$ from $5$ to $10$, i.e., $10-4=6$ times. That is, every time the middle loop is entered, the innermost loop runs $6$ times, so the print statement is executed $6\cdot8=48$ times.

Can you finish it from there? How often is the middle loop entered?

share|improve this answer
    
Thank you very much :) –  Peter Ji Oct 10 '12 at 0:56
    
@Peter: You’re welcome. –  Brian M. Scott Oct 10 '12 at 0:59
    
@BrianM.Scott: Is the print command executed when $k=8$? Or is it possible to stop the process when $k=8$? Will this depend on the program language? –  Sigur Oct 10 '12 at 1:44
1  
@Sigur: I’m assuming that downto works like to, which in every language that I’ve used includes the limit. –  Brian M. Scott Oct 10 '12 at 1:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.