I'm stumped on this assignment. C hasn't really been coming easy for me so I would appreciate some help!
Problem 1: Is It Prime?
Write a C program that takes a positive integer on the standard input (aka, user input) and prints ”prime” or ”composite” or ”unit” (A number is a unit if it is 1, prime if it is divisible only by 1 and itself (and is not 1), and composite otherwise). I recommend using the % modulus operator, as it returns the remainder of dividing two numbers. n % x == 0 only if x evenly divides n. Using loops, particular a for loop, would be quite advantageous. Example input and output:
Enter a number: 6 composite
Problem 2: Guess My Number
You are going to generate a random number between 1 and 10. Remember to include time.h. At the beginning of the main function, use the following:
//This seeds the random generator using the current time . srand (time(NULL));
Then you can get a random number between 1 and 10 using:
int r = rand () % 10 + 1;
Let the user keep guessing until they get it correct. Then output how many guesses it took. OPTIONAL: Tell them whether they are too high or too low.
I am thinking of a number between 1 and 10.
Your guess : 5 Incorrect . Guess again : 7 Incorrect . Guess again : 2 Correct ! Number of guesses : 3.
thank you very much for your help