C programming help
Thread Starter
Senior Member
Joined: May 2010
Posts: 126
Likes: 0
From: Boston, Massachusetts
Vehicle: 2000 Hyundai Tiburon
Hey guys I need to make a program that lists out prime numbers until it is interrupted with the
Control-C interrupt signal. I need to use fork()to create multiple processes, each of which has the job
of testing one prime. The main program collects the exit status of each child process and uses that to
figure out if the number should be outputted to the screen. The output must be formatted to 8 primes per
line, and continue until the main program is interrupted. The output will look like this:

Can anyone write this?
Control-C interrupt signal. I need to use fork()to create multiple processes, each of which has the job
of testing one prime. The main program collects the exit status of each child process and uses that to
figure out if the number should be outputted to the screen. The output must be formatted to 8 primes per
line, and continue until the main program is interrupted. The output will look like this:

Can anyone write this?
Thread Starter
Senior Member
Joined: May 2010
Posts: 126
Likes: 0
From: Boston, Massachusetts
Vehicle: 2000 Hyundai Tiburon
Moderator


Joined: Feb 2009
Posts: 11,732
Likes: 5
From: Leesville, Louisiana
Vehicle: 2001 Hyundai Tiburon
This is a rediculous question and you should drop the class if you cannot figure it out. You asked a question before on C programming help which I requested to know more and you did not answer.
Ok, so for the help portion of this... I don't do C, but I can pseudocode some stuff for you.
Note, this will get you as high as the Double value can test.. that is the limitation.
Ok, so for the help portion of this... I don't do C, but I can pseudocode some stuff for you.
Code:
#a prime is a number which cannot be divided by any number except 1 and itself.
integer testprime(int Number) {
#make a counter to check.
int ReverseCounter=Number
Double result=0
#loop through all numbers less then the Number to check and greater then 0
while ( ReverseCounter > 1 ){
((--ReverseCounter))
result=Number/ReverseCounter
if ( ((int)Result)-Result == 0) {
#if the result, casted as an integer, is a whole number, then return with status 1
return 1
}
}
#if we made it through the loop without returning a whole number, then return 0
return 0
}
void Main() {
int Number=0
#loop through all numbers, fork processes.
while (true) {
#I don't know the syntax of the fork() command, but fork the process here
#Test the output status
#if the output status is 0 print, else don't print
}
}
I'm afraid that unless he KNOWS C, he won't be able to transfer that and compile it
I spent three semesters programming Java, and while I understand the language enough to read it, I couldn't write anything today (4 years later)
I spent three semesters programming Java, and while I understand the language enough to read it, I couldn't write anything today (4 years later)
Moderator


Joined: Feb 2009
Posts: 11,732
Likes: 5
From: Leesville, Louisiana
Vehicle: 2001 Hyundai Tiburon
Java and c share very similar syntax. To make this work in c, it's a matter of changing a few symbols to c language.
When I program, I have google on one monitor looking up examples and syntax while I do the actual programming and debugging on the other.
For this example, you take the code above and debug it until it matches C syntax with no errors and compiles properly.Programming is not easy and even the best programmers need a reference when dealing with new commands.
Besides. I used as much c syntax as I could so some lines are syntactically correct..
When I program, I have google on one monitor looking up examples and syntax while I do the actual programming and debugging on the other.
For this example, you take the code above and debug it until it matches C syntax with no errors and compiles properly.Programming is not easy and even the best programmers need a reference when dealing with new commands.
Besides. I used as much c syntax as I could so some lines are syntactically correct..



