Help with this question pleeeasse

dellboy1234

New member
Joined
Dec 19, 2015
Messages
2
The following is a piece of code from a program

total_sum=2

For count1=3 To Step 2

MatchFlag=FALSE

For count2=2 TO INT(count1^0.5)

If INT(count1/count2)=count1/count2 Then MatchFlag=TRUE

Next count2

If MatchFlag=FALSE Then total_sum=total_sum+count1

Next count1

What does this code doand what valueis contained in the variable total_sum?

Notes

1. The line for "count1=x to To y Step z" means a loop is created in which count1 first takes value x, then x+z and so on until it equals (or exceeds) y
2. INT is a function that returns the integer part of any real number

Thanks for your help!!!!
 
The following is a piece of code from a program

total_sum=2

For count1=3 To Step 2

MatchFlag=FALSE

For count2=2 TO INT(count1^0.5)

If INT(count1/count2)=count1/count2 Then MatchFlag=TRUE

Next count2

If MatchFlag=FALSE Then total_sum=total_sum+count1

Next count1

What does this code doand what valueis contained in the variable total_sum?

Notes

1. The line for "count1=x to To y Step z" means a loop is created in which count1 first takes value x, then x+z and so on until it equals (or exceeds) y
2. INT is a function that returns the integer part of any real number

Thanks for your help!!!!
How about you play computer and go through first couple of iterations by hand (paper & pencil)

What are your thoughts?

Please share your work with us ...even if you know it is wrong

If you are stuck at the beginning tell us and we'll start with the definitions.

You need to read the rules of this forum. Please read the post titled "
Read before Posting" at the following URL:

http://www.freemathhelp.com/forum/th...Before-Posting
 
The following is a piece of code from a program

total_sum=2

For count1=3 To Step 2

MatchFlag=FALSE

For count2=2 TO INT(count1^0.5)

If INT(count1/count2)=count1/count2 Then MatchFlag=TRUE

Next count2

If MatchFlag=FALSE Then total_sum=total_sum+count1

Next count1

What does this code doand what valueis contained in the variable total_sum?

Notes

1. The line for "count1=x to To y Step z" means a loop is created in which count1 first takes value x, then x+z and so on until it equals (or exceeds) y
2. INT is a function that returns the integer part of any real number

Thanks for your help!!!!
See red above - this piece of code seems wrong.

Assuming the code were fixed, since INT(3^0.5) = 1, the first count2 loop may or may not execute depending on the compiler and language used. That is, part of the answer could depend on just what your compiler does. In the (maybe not so distant) past some compilers checked conditions at the end of the loop [causing 'for loops' to always be executed at least once] and some compilers checked at the beginning [causing some 'for loops' to not be executed at all]. That could also depend on the language used.

Oh, and I agree with Subhotosh Khan, get out a pencil and paper (or equivalent) and go through a few cycles.
 
Top