# Sum of prime numbers between 2 numbers

Page 1 of 1

## 4 Replies - 14946 Views - Last Post: 20 November 2008 - 09:45 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=72756&amp;s=5db1f5ce049f4f26d6ad311b9e743214&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Kasra_olips

Reputation: 0
• Posts: 2
• Joined: 20-November 08

# Sum of prime numbers between 2 numbers

Posted 20 November 2008 - 08:02 AM

Hi dears.
I have a simple question about c++.

how I can sum of prime numbers between 50 & 100 and print it?
what is codes?

tanx a lot.
Is This A Good Question/Topic? 0

## Replies To: Sum of prime numbers between 2 numbers

### #2 muballitmitte

• D.I.C Regular

Reputation: 174
• Posts: 470
• Joined: 05-November 08

## Re: Sum of prime numbers between 2 numbers

Posted 20 November 2008 - 08:44 AM

[rules]
[/rules]

### #3 Kasra_olips

Reputation: 0
• Posts: 2
• Joined: 20-November 08

## Re: Sum of prime numbers between 2 numbers

Posted 20 November 2008 - 09:01 AM

muballitmitte, on 20 Nov, 2008 - 07:44 AM, said:

[rules]
[/rules]

http://dreamincode.c...wtopic25403.htm
its about vb, and you did it. But now u cant? its unfair.

Its not my homework, one of my freinds ask it.
I know this code to find prime numbers between 1 & 1000:
``` for i:=2 to 1000 do begin
sw:=0;
for j:=2 to (i div 2)+1 do begin
if (i mod j)=0 then begin sw:=1; break; end
end;
if sw=0 then writeln(i);
end;
```

Now I want sum of prime numbers between 50 & 100 and print it.

### #4 Jayman

• Student of Life

Reputation: 421
• Posts: 9,532
• Joined: 26-December 05

## Re: Sum of prime numbers between 2 numbers

Posted 20 November 2008 - 09:11 AM

Post the code that you have completed in your attempt to fulfill this projects requirements.

Regardless of whether this is for a friend or you, you must show at least a minimum amount of effort at solving the problem.

### #5 DaneAU

• Great::Southern::Land

Reputation: 286
• Posts: 1,620
• Joined: 15-May 08

## Re: Sum of prime numbers between 2 numbers

Posted 20 November 2008 - 09:45 AM

```#include <iostream>

using namespace std;

void printPrime(int x, int y);

int main()
{
printf("============================\nPrimes Program\nCoder: [email protected]\n============================\n\n");
printPrime(150,50);    //print primes up to for 50 - 150

getchar();
return 0;
}

//function
void printPrime(int x, int y)
{
int maximum = x;
int initial = y;
int j ,counter;

while(initial <= maximum)
{
counter = 0;    //reset to zero each loop
for(j = 1; j <= initial; j++)
{
if( initial%j == 0 )
counter++;
}

if(counter == 2)
printf("%d	", initial);

initial++;
}
printf("\n");

}

```

This post has been edited by bbq: 20 November 2008 - 09:45 AM