Question

In: Computer Science

Part 2 Write a C code to create 5 random numbers between 90 and 100 (included)...

Part 2

Write a C code to create 5 random numbers between 90 and 100 (included) and print the values on the screen.

Part 3

Create a function that will mimic throwing the dice twice. The function will do the following when you call it.

  • The function will generate 2 random numbers between 1 and 6
  • The function will display the two random numbers to the user
  • The function will display “Winner” if the sum of the two numbers are 7 or 11

The function will display “hard luck” otherwise

Solutions

Expert Solution

part2:

#include<stdio.h>
#include<time.h>
#include<stdlib.h>

int main()
{
    int upper=100,lower=90; //Taking upper limit as 100 and lower limit as 90.
    int i,num;
    printf("Five random number between 90 and 100:\n\n");
    srand(time(0));//by this we generate new batch of random numbers every time we run the programm.
    for(i=0;i<5;i++)
    {
        //use rand function to generate random numbers
        num=(rand()%(upper-lower+1))+lower; //(rand()%(upper-lower+1))+lower formula for generate random number between range.
        printf("%d\t",num);//show output on screen
    }
    return 0;
}

part 3:

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
void throwdice()
{
    int upper=6,lower=1; //Taking upper limit as 6 and lower limit as 1.
    int firstnumber,secondnumber;
    int num,i;
    //use rand function to generate random numbers
    for(i=0;i<2;i++)
    {
        //use rand function to generate random numbers
        num=(rand()%(upper-lower+1))+lower; //(rand()%(upper-lower+1))+lower formula for generate random number between range.
        if(i==0)
        {
            firstnumber=num;//store first random number when i==0
        }
        if(i==1)
        {
            secondnumber=num;//store second random number when i==1
        }
    }
    printf("Two random number are: %d  %d\n",firstnumber,secondnumber);//show two random numbers
    if(firstnumber+secondnumber==7 || firstnumber+secondnumber==11)//checking condition as given in question
    {
        printf("\nWinner\n");
    }
    else
    {
        printf("\nHard luck\n");
    }
}
int main()
{
    srand(time(0));//by this we can generate new random numbers every time when we run the program.
    throwdice(); //calling function
    return 0;
}

I also merge two program if u required:

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
void throwdice()
{
    int upper=6,lower=1; //Taking upper limit as 6 and lower limit as 1.
    int firstnumber,secondnumber;
    int num,i;
    //use rand function to generate random numbers
    for(i=0;i<2;i++)
    {
        //use rand function to generate random numbers
        num=(rand()%(upper-lower+1))+lower; //(rand()%(upper-lower+1))+lower formula for generate random number between range.
        if(i==0)
        {
            firstnumber=num;//store first random number when i==0
        }
        if(i==1)
        {
            secondnumber=num;//store second random number when i==1
        }
    }
    printf("Two random number are: %d  %d\n",firstnumber,secondnumber);//show two random numbers
    if(firstnumber+secondnumber==7 || firstnumber+secondnumber==11)//checking condition as given in question
    {
        printf("\nWinner\n");
    }
    else
    {
        printf("\nHard luck\n");
    }
}
int main()
{
    int upper=100,lower=90; //Taking upper limit as 100 and lower limit as 90.
    int i,num;
    printf("Five random number between 90 and 100:\n\n");
    srand(time(0));
    for(i=0;i<5;i++)
    {
        //use rand function to generate random numbers
        num=(rand()%(upper-lower+1))+lower; //(rand()%(upper-lower+1))+lower formula for generate random number between range.
        printf("%d\t",num);//show output on screen
    }
    printf("\n\n");
    throwdice();
    return 0;
}

plss like if u like my answer.


Related Solutions

Question1; Write a c++ program that prints all natural numbers between 10(included) to 100(included) by the...
Question1; Write a c++ program that prints all natural numbers between 10(included) to 100(included) by the while loop. question2: Write a C++ program that prints all numbers between 10 to 1000 that are divisible by 5
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100...
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100 and 300. Pick a number at random out of these 50 random variables. a. Determine the probability of the chosen number being greater than 200. This may be achieved by counting the numbers that are greater than 200 and dividing the count by 50. Make sure you, i.Formulate the appropriate if-conditions to check for a number being greater than 200 ii. Use a for-loop...
Part 2 Write a C code to create a user defined function called RecArea that will...
Part 2 Write a C code to create a user defined function called RecArea that will calculate the area of a rectangle. Call the function to print the area of the rectangle on the screen. Note: The user will enter the length and width of a rectangle (decimal values, float) and you Part 3 (Continue on part 2) Create another user defined function called TriArea that will calculate the area of a triangle. Print the area of the rectangle on...
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers....
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers. Record the time. Run Bubble Check time (compute the processing time) do it 100 times (random numbers) Take the average Insertion: Compare] (some explanations please)
Use VB.net to create a loop that posts the first 100 prime numbers. Then, write code...
Use VB.net to create a loop that posts the first 100 prime numbers. Then, write code to confirm the numbers are prime.
To generate 100 random numbers between 1-100 in a randomData.txt file To read the 100 random...
To generate 100 random numbers between 1-100 in a randomData.txt file To read the 100 random numbers from randomData.txt and store them in an array Print the data in the array Find the smallest and the largest of the random numbers and their array position Insert an element of value100 in the 51th position of the array Delete all the elements of the array having values between 50-80 and print the residual array Sort the data in the final array(residual)...
****java*** Create an application that generates 20 random numbers between 1 and 100 and writes them...
****java*** Create an application that generates 20 random numbers between 1 and 100 and writes them to a text file on separate lines. Then the program should read the numbers from the file, calculate the average of the numbers, and display this to the screen.
Write a Java program that creates an array with 20 random numbers between 1 and 100,...
Write a Java program that creates an array with 20 random numbers between 1 and 100, and passes the array to functions in order to print the array, print the array in reverse order, find the maximum element of the array, and find the minimum element of the array. The prototype of the methods: public static void printArray(int arr[]) public static void printArrayReverse(int arr[]) public static int searchMax(int arr[]) public static int searchMin(int arr[]) Sample output: Random Array: [17 67...
Write a program in PERL language that does the following: a. Generates 100 random numbers between...
Write a program in PERL language that does the following: a. Generates 100 random numbers between -17 and +31. b. Calculates the average of the square of the generated numbers using a function that you implement. c. Calculates the number of numbers greater than the average using a function that you implement. d. Prints the results single line separated by spaces using a print function that makes call to the previously defined functions in parts b) and c).
2)  Suppose I use a random numbers table to randomly choose 900 numbers between 0 and 100....
2)  Suppose I use a random numbers table to randomly choose 900 numbers between 0 and 100. In this particular sample, the mean of the 900 numbers is 50 and the standard deviation is 30. a)Approximately, what proportion of the 900 numbers should fall between 20 and 80 (inclusive)? b)Suppose each student in Static (class size = 140) repeats the experiment described above and computes the mean of his or her 900 numbers. Based on the information given above, estimate the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT