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.
4 Replies  9188 Views  Last Post: 20 November 2008  09:45 AM
Replies To: Sum of prime numbers between 2 numbers
#2
Re: Sum of prime numbers between 2 numbers
Posted 20 November 2008  08:44 AM
[rules]
[/rules]
[/rules]
#3
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]
[/rules]
see this thread:
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
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.
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
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: bbq@dreamincode.com\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
Page 1 of 1
