I need help with a program !

The program is to print out a list of the prime numbers in the range 1-100.
I hope this can help you

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream.h>

bool isprimenumber(unsigned long n) {
	bool result;
	if(n == 0) {
		result = false;
	}
	else {
		result = true;
		if(n > 1)
			for(unsigned long i = 2; i < n; i++)
				result = result && ( (n % i) != 0 );
	}
	return result;
}

void main() {
	for(int i = 1; i <= 100; i++)
		if(isprimenumber(i))
			cout << i << endl;
}
hope this help you

#include <iostream.h>
#include <conio.h>

int main()
{
clrscr();
int a;
for(a=1;a<=100;a++)
{
if (((a%2)!=0)&&((a%3)!=0)&&((a%5)!=0)&&((a%7)!=0))
cout << a << " ";
}
getch();
return 0;
}
HI ALL ! i think all here are newbies and need not only some help but the most important is to benefit and learn, i appreciat what Alex79roma and prize16 did. look sayak38kolay, i know that u r new in programing and it is not a problem but u should depend on urself in most cases as beginner, i mean the way u ask for help is somehow wrong( sorry for this) if u got a program to solve, solve it first in ur way then if u got any difficult ask for help this way i garanty ur to improv so fast in programing, but if u depend on the other code then do urs :(.....
so as a friend i just wanna advice to try to solve the code first then if u face any problem we can discus it, this way u ll realy undrestand and compare the ohter code and ur so u ll see what are u mistake.
sorry for this but just an advice as a friend hope no feeling hurt ;).
:).
HI ALL ! i think all here are newbies and need not only some help but the most important is to benefit and learn, i appreciat what Alex79roma and prize16 did. look sayak38kolay, i know that u r new in programing and it is not a problem but u should depend on urself in most cases as beginner, i mean the way u ask for help is somehow wrong( sorry for this) if u got a program to solve, solve it first in ur way then if u got any difficult ask for help this way i garanty ur to improv so fast in programing, but if u depend on the other code then do urs :(.....
so as a friend i just wanna advice to try to solve the code first then if u face any problem we can discus it, this way u ll realy undrestand and compare the ohter code and ur so u ll see what are u mistake.
sorry for this but just an advice as a friend hope no feeling hurt ;).
:).
Ladies and Gentlemen, I present to you: The Sieve of Eratosthenes!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <math.h>
#define LIMIT 100
#define MAX sqrt(LIMIT)
bool isprime [LIMIT];

using namespace std;
int main()
{
	for (int b = 2; b < LIMIT; b++) isprime[b] = true;
	cout << MAX << endl;
	for (int i = 2; i < MAX; i++) {
		if(!isprime[i]) continue;
		for (int j = i*i; j < LIMIT; j+= i) isprime[j] = false;
	}
	for (int i = 2; i < LIMIT; i++) if(isprime[i]) cout << i << endl;
	return(0);
}


http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

EDIT: Don't just say 'I need help with a program'. Of course you do; that's why you're posting here.
Last edited on
Topic archived. No new replies allowed.