Computers, Gaming, & Technology Here you can talk about anything with circuit boards, or dilithium crystals, or flux capacitors. Show off your technology, computing, and gaming knowledge.

C programming help

Thread Tools
 
Old 12-07-2010, 07:58 AM
  #1  
Senior Member
Thread Starter
 
AtomicX's Avatar
 
Join Date: May 2010
Location: Boston, Massachusetts
Posts: 126
Likes: 0
Received 0 Likes on 0 Posts
Vehicle: 2000 Hyundai Tiburon
Default C programming help

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?
Old 12-07-2010, 08:06 AM
  #2  
Administrator
 
majik's Avatar
 
Join Date: Oct 2002
Location: ɯooɹpǝq ɹnoʎ
Posts: 13,943
Likes: 0
Received 0 Likes on 0 Posts
Vehicle: ǝdnoɔ sısǝuǝƃ
Default

You mean do your homework for you? :paranoid: I hope you aren't planning to write our next encryption algorithm
Old 12-07-2010, 08:07 AM
  #3  
Senior Member
Thread Starter
 
AtomicX's Avatar
 
Join Date: May 2010
Location: Boston, Massachusetts
Posts: 126
Likes: 0
Received 0 Likes on 0 Posts
Vehicle: 2000 Hyundai Tiburon
Default

Its my last one, and I cant figure it out
Old 12-07-2010, 08:47 AM
  #4  
Administrator
 
majik's Avatar
 
Join Date: Oct 2002
Location: ɯooɹpǝq ɹnoʎ
Posts: 13,943
Likes: 0
Received 0 Likes on 0 Posts
Vehicle: ǝdnoɔ sısǝuǝƃ
Default

I'm just giving you a hard time. I'd help if I could.



Seems like a fairly popular project. I'm sure Google could help in some way ??
Old 12-07-2010, 08:55 AM
  #5  
Senior Member
Thread Starter
 
AtomicX's Avatar
 
Join Date: May 2010
Location: Boston, Massachusetts
Posts: 126
Likes: 0
Received 0 Likes on 0 Posts
Vehicle: 2000 Hyundai Tiburon
Default

Originally Posted by majik
I'm just giving you a hard time. I'd help if I could.



Seems like a fairly popular project. I'm sure Google could help in some way ??
I tried I can't find anything =[ I really need help
Old 12-07-2010, 10:00 AM
  #6  
Senior Member
Thread Starter
 
AtomicX's Avatar
 
Join Date: May 2010
Location: Boston, Massachusetts
Posts: 126
Likes: 0
Received 0 Likes on 0 Posts
Vehicle: 2000 Hyundai Tiburon
Default

I'm willing to pay $50 to whoever can solve this for me, I can Include more instructions through PM
Old 12-07-2010, 11:16 AM
  #7  
DTN
Moderator
 
DTN's Avatar
 
Join Date: Feb 2009
Location: Leesville, Louisiana
Posts: 11,731
Received 5 Likes on 5 Posts
Vehicle: 2001 Hyundai Tiburon
Default

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.



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

 }

}
Note, this will get you as high as the Double value can test.. that is the limitation.
Old 12-07-2010, 12:49 PM
  #8  
Administrator
 
majik's Avatar
 
Join Date: Oct 2002
Location: ɯooɹpǝq ɹnoʎ
Posts: 13,943
Likes: 0
Received 0 Likes on 0 Posts
Vehicle: ǝdnoɔ sısǝuǝƃ
Default

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)
Old 12-07-2010, 02:24 PM
  #9  
DTN
Moderator
 
DTN's Avatar
 
Join Date: Feb 2009
Location: Leesville, Louisiana
Posts: 11,731
Received 5 Likes on 5 Posts
Vehicle: 2001 Hyundai Tiburon
Default

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..




All times are GMT -6. The time now is 03:39 PM.