In: Computer Science
C programming:
Define a function computer_choose that chooses a random integer between 1 and 1000 (inclusive).
Note: the tests call your function 1000 times to verify that no results are <0 or >1000. Rarely, this can score an incorrect function as correct.
#include <stdio.h>
#include <stdlib.h>
//function to generate a random number
int computer_choose()
{
int randNum;
//generate a random number between 1 and 1000(inlcusive)
randNum = rand() % 1000 + 1;
return randNum;
}
int main()
{
//for loop to generate random number 1000 times
for(int i=0; i<1000; i++)
{
if(i!=0 && i%15==0)
printf("\n");
//display random number on the computer screen
printf("%5d ",computer_choose());
}
return 0;
}
OUTPUT: