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 Dec 7, 2010 | 07:58 AM
  #1  
AtomicX's Avatar
Thread Starter
Senior Member
 
Joined: May 2010
Posts: 126
Likes: 0
From: Boston, Massachusetts
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?
Reply
Old Dec 7, 2010 | 08:06 AM
  #2  
majik's Avatar
Administrator
 
Joined: Oct 2002
Posts: 13,943
Likes: 0
From: ɯooɹpǝq ɹnoʎ
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
Reply
Old Dec 7, 2010 | 08:07 AM
  #3  
AtomicX's Avatar
Thread Starter
Senior Member
 
Joined: May 2010
Posts: 126
Likes: 0
From: Boston, Massachusetts
Vehicle: 2000 Hyundai Tiburon
Default

Its my last one, and I cant figure it out
Reply
Old Dec 7, 2010 | 08:47 AM
  #4  
majik's Avatar
Administrator
 
Joined: Oct 2002
Posts: 13,943
Likes: 0
From: ɯooɹpǝq ɹnoʎ
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 ??
Reply
Old Dec 7, 2010 | 08:55 AM
  #5  
AtomicX's Avatar
Thread Starter
Senior Member
 
Joined: May 2010
Posts: 126
Likes: 0
From: Boston, Massachusetts
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
Reply
Old Dec 7, 2010 | 10:00 AM
  #6  
AtomicX's Avatar
Thread Starter
Senior Member
 
Joined: May 2010
Posts: 126
Likes: 0
From: Boston, Massachusetts
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
Reply
Old Dec 7, 2010 | 11:16 AM
  #7  
DTN's Avatar
DTN
Moderator
 
Joined: Feb 2009
Posts: 11,732
Likes: 5
From: Leesville, Louisiana
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.
Reply
Old Dec 7, 2010 | 12:49 PM
  #8  
majik's Avatar
Administrator
 
Joined: Oct 2002
Posts: 13,943
Likes: 0
From: ɯooɹpǝq ɹnoʎ
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)
Reply
Old Dec 7, 2010 | 02:24 PM
  #9  
DTN's Avatar
DTN
Moderator
 
Joined: Feb 2009
Posts: 11,732
Likes: 5
From: Leesville, Louisiana
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..
Reply




All times are GMT -6. The time now is 11:21 PM.