Who knows how to resolve this, has an award. Seriously, who can resolve this, will get an award which he/she will put on his/her blog 🙂 !
a) Show that if a natural number has only three divisors, it is the square of a prime number
b) Show that if a natural number has only four divisors, it is the cube of a prime number or the product of two prime numbers.
Below is a program that uses the random function .
int secret; //declaration for variable “secret”
srand (time(NULL)); // initialize random function
secret = rand() % 10+1; // variable is assigned a value
printf(“%d”,secret); //dipslay the variable’s value on the screen
Let’s explain what happens when I write “secret=rand()%10+1;”
If I wrote secret=rand(); the program will display any number between -231 and +231
(because the number was declareted integer (int) and there are the limits for integer)
%10 is the function which give the rest of the divizion at 10 ; this function is avabile for each number. In this case we have %10 = the last digit of the number (it can be between 0 and 9) . At the result we add 1 , that means the random number which will be display, will be between 1 and 10.
// means commnent – you can run the program with coments
Read and try to aply this function 😉 !
Someone ask me “What print(“%d”,nr); means ? And somewhere I saw exactly the same sequence but with printf. Can you enlighten me ?”
Surely, I can explain you. Let’s take step by step.
printf – the function for display “nr” ON SCREEN
%d – a integer variable
nr – the variable which will display ON SCREEN
; – at the end of each instruction you must ;
You saw that I laid emphasis on the fact that displays on-screen. Why ? Because the function printf (not print) is the same function, but printf will display the variable “nr” in a file.
The program run and display the value must display only if you declared correctly.
1) At beginning of the program you must declared the variable like this :
2) The variable’s value must be read or you must attribute a value at the variable
nr=33; (33 is only an example)
Don’t forget ! ! ! At reading you must put & , but when you display the variable you don’t must put this. If you don’t make like this, the program will return an error.