Respuesta :
Answer:
The program of random number in C language can be given as:
Program:
//header file.
#include <stdio.h>
#include <stdlib.h>
//main function
int main()
{
//define variable.
int myRandomNumber;
srand(time(NULL));
// seed the random number generator
myRandomNumber = rand(); //random number hold in variable.
printf("Number is %d\n", myRandomNumber );
//check for even number.
if(myRandomNumber % 2 == 0)
{
printf("Number %d is even number\n",myRandomNumber);
}
else //condition false.
{
printf("Number %d is odd number\n",myRandomNumber);
}
//checking number divisible by 3.
if(myRandomNumber % 3 == 0)
{
printf("Number %d is divisible by 3\n",myRandomNumber);
}
else //condition false.
{
printf("Number %d is not divisible by 3\n",myRandomNumber);
}
//checking number divisible by 10.
if(myRandomNumber % 10 == 0){
printf("Number %d is divisible by 10\n",myRandomNumber);
}
else //condition false.
{
printf("Number %d is not divisible by 10\n",myRandomNumber);
}
return 0;
}
Output:
Number is 1096297062
Number 1096297062 is even number
Number 1096297062 is divisible by 3
Number 1096297062 is not divisible by 10
Explanation:
In the above C language program firstly we declare a variable i.e (myRandomNumber). It will used for holding the number. Then we check the number is even or odd. for checking number we use condition i.e.(myRandomNumber %2 ==0). In that condition the number is divided by 2 . If the remainder is 0 then it is even number. otherwise it is odd. Similarly we divide the number by 3 and 10. if the number is divisible then we print number is divisible otherwise we print number is not divisible.