Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Finding the sum of all prime numbers between 100 and 200

$
0
0
Hello guys,
I'm new to this board and fairly new to programming as well. I've recently been given a problem that i am a bit stuck on. I am told to find the prime numbers between 100 to 200 then display the sum of these numbers. I know how to find the prime numbers of a given pair but incorporating the sum is giving me some trouble. I'm not sure if using a for loop as opposed to a do while and add counter is the best method but here is what i have so far.

Dim c, num As Integer
For c = 100 To 200
For num = 2 To (c - 1)
If c Mod num = 0 Then
Exit For
End If
Next num
If c = num Then
ListBox1.Items.Add©
End If
Next
End Sub

End Class

As of now the program just displays all 21 prime numbers. I would love some help and ideas(not asking anyone to do it for me, rather then push me in the right direction) as to how to incorporate the other portion of this problem.

Thanks,
Ben

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>