Question

In: Computer Science

C programming: Define a function computer_choose that chooses a random integer between 1 and 1000 (inclusive)....

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.

Solutions

Expert Solution

#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:


Related Solutions

we saw a C program called GuessNumber.c that generates a random integer between 1 and 1000...
we saw a C program called GuessNumber.c that generates a random integer between 1 and 1000 and asks the user to guess that number. Modify the program so that at the end of each round, it also prints the number of guesses made by the user to reach the answer as well as the best score so far, i.e., the minimum number of guesses used in any round since the program was started. The source code of the original version...
Challenge 4 – Random Integer in Range Write a function to return a random integer between...
Challenge 4 – Random Integer in Range Write a function to return a random integer between a minimum value and maximum value. var ival = IntRandomRange(, );
import random # define functions def rollDice(): # function returns a random number between 1 and...
import random # define functions def rollDice(): # function returns a random number between 1 and 6 def userWon(t1, t2): # function accepts player total and computer total # function returns true if player wins # function returns false if computer wins def main(): # each player rolls two Dice player = rollDice() + rollDice() computer = rollDice() + rollDice() # ask the player if they want to roll again again = int(input("Please enter 1 to roll again. Enter 2...
Suppose you ask a friend to randomly choose an integer between 1 and 10, inclusive. What...
Suppose you ask a friend to randomly choose an integer between 1 and 10, inclusive. What is the probability that the number will be more than 5 or odd? (Enter your probability as a fraction.) Two dice are rolled. Determine the probability of the following. ("Doubles" means both dice show the same number.) rolling a 4 or doubles Use the data in the table below, which shows the employment status of individuals in a particular town by age group. Age...
Java Language The int t contains an integer between 1 and 50 (inclusive). Write code that...
Java Language The int t contains an integer between 1 and 50 (inclusive). Write code that outputs the number in words and stores the result in the String inwords. For example, if t is 35 then inwords should contain "thirty five". Test Cases Test case #1 Expected result: When t is 2, your code sets inwords to "two" Test case #2 Expected result: When t is 50, your code sets inwords to "fifty" Test case #3 Expected result: When t...
The array s of ints contain integers each of which is between 1 and 1000 (inclusive)....
The array s of ints contain integers each of which is between 1 and 1000 (inclusive). Write code that stores in the variable ordinals the array of Strings consisting of each number followed by its ordinal number abbreviation, "st", "nd", "rd", or "th". For example if s is the array { 1, 2, 3, 4, 5, 10, 11, 12, 13, 21, 22, 973, 1000 } then your code should set ordinals to the array { "1st", "2nd", "3rd", "4th", "5th",...
Define a function ?∶ ℝ→ℝ by ?(?)={?+1,[?] ?? ??? ?−1,[?]?? ???? where [x] is the integer...
Define a function ?∶ ℝ→ℝ by ?(?)={?+1,[?] ?? ??? ?−1,[?]?? ???? where [x] is the integer part function. Is ? injective? (b) Verify if the following function is bijective. If it is bijective, determine its inverse. ?∶ ℝ\{5/4}→ℝ\{9/4} , ?(?)=(9∙?)/(4∙?−5)
You can use any programming languages Using a random generator, compute 1000 integers between 1 and...
You can use any programming languages Using a random generator, compute 1000 integers between 1 and 1000. There will be duplicates in the array. Sort the array using bubble sort and merge sort. The two sorted arrays should agree. Then pick at random one element from your sorted array and use a binary search to find its position in the array.
(c) Explain TWO (2) differences between int and Integer in the context of Java programming using...
(c) Explain TWO (2) differences between int and Integer in the context of Java programming using suitable example,
C# Programming create a Hash Function
C# Programming create a Hash Function
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT