View Single Post
Old Mar 20th, 2005, 12:55 AM   #3
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
It's not a tough program at all. Write a function to determine whether it's prime or not. In the function, have an int variable which stores whether the number is prime or not -- 1 for prime and 0 for not prime. Initialize it to 1. Have it run through a loop from 2 up to 1 below the number you're testing for. If it's evenly divisible, then set the value to 0 . . .

 
 #include <stdio.h>
 
 #define PRIME 1
 #define NOT_PRIME 0
 
 int main(void)
 {
 	 // some code
 	 // ...
 	 // ...
 	 int isPrime = checkPrime(number);
 }
 
 int checkPrime(int num)
 {
 	 int value = PRIME;
 	 int i = 2;
 	 for(i; i<num; i++)
 	 {
 		  if(i%num==0)
 			   value = NOT_PRIME;
 	 }
 	 return value;
 }
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote