If you mean EVERY even number between 1 and 100 then here is an example:
If you mean a selection of numbers between 1 and 100 then build off of dynamic_sysop's post.VB Code:
'loop thru 1(2 since 1 is odd) to 100 skipping every other one (step 2) Dim sum As Integer Dim count As Integer For nmbr As Integer = 2 To 100 Step 2 'increment the count count += 1 'add to the sum sum += nmbr Next 'get average Dim result As Single = sum / count 'build a string to show results Dim sb As New System.Text.StringBuilder sb.Append(String.Format("There a {0} even numbers between 1 and 100.{1}", count, ControlChars.NewLine)) sb.Append(String.Format("The sum of these numbers is {0}.{1}", sum, ControlChars.NewLine)) sb.Append(String.Format("The average of these numbers is {0}.", result)) 'show results string MsgBox(sb.ToString)




Reply With Quote