5
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by stultuske
0

follow these steps:
1. let say you need to findout all the primes till number n
2. create a outer for loop which will iterate from 1 to n (let say int i)
3. create a inner for loop(int j) and chk i%j
4. for prime numbers i%j will be 0

0

Or

private boolean is_prime(int n) {
for(int i=2; n<i*i; i++) {
if(i*i==n) {
return true;
}
/*
or
if(n%i==0) {
return true;
}
*/
}
return false; 
}

/* main */
int num = 123;
for(int i=2; i<num; i++) {
if(is_prime(i)==true) {
System.out.println(i);
}
}

But this code is not tested.

Edited by Krstevski: n/a

0

Or

...

But this code is not tested.

don't just hand out code. the purpose of this forum is to help him learn the language, not to do his work for him and help him cheat his way through college

0

And if they did use that code they won't be graduating from any college soon. It doesn't do a whole lot of much.

0

maybe, but doens't change the fact that a lot of 'students' are willing to pass with the minimum required grades

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.