hello, im trying to write a program that will find all the prime numbers in a given field. i've been reading forums ad looking at examples, but i cant comprehend it, so i figured it was time to make a post. i don't really know where to start. the only thing i can think of doing is having the program divide every number up to teh max i set by every number and only print the ones that are divisible by 1 and itself. this seems like a very primitive process and i'm wondering if there is an easier way to do it.

# finding prime numbers with c

0

0

0

0

Quote:

Originally Posted bystefan1989I literally started c like 2 days ago lol and have been scouring forums trying to learn more.

I will help you with some flow chart type of thing

1. Read the content in to the array

2. Loop through then something like this pseudo code

Code:

for(int i = 2;i<n/2;i++) { if(n % i == 0) // n is not prime and set the flag } if(flag not set) Number is prime

0

Ok, here is what i've got so far

Code:

#include <stdio.h> #include <conio.h> main() { int i; for(int i=2;i<n/2;i++) { if(n%i==0) } if(n%i???) don't know what goes here. if(i) ?? printf("%d",i); }

*Last edited by shabbir; 20Apr2007 at 18:20.. Reason: Code block*

0

Code:

for(int i=2;i<n/2;i++) { if(n%i==0) }