Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note: Global variables are only allowed to be used if it is mentioned in the problem Topics covered in this homework Functions, recursive functions, static,

image text in transcribed
Note: Global variables are only allowed to be used if it is mentioned in the problem Topics covered in this homework Functions, recursive functions, static, local, and global variables Solve ALL the problems listed below. For each problem, you need to provide a copy of your source code and a screenshot of the output of the program when you run it. You should put everything together in one report and upload a PDF version of your report to webcourse. 1. Write a function "int roll diel int num sides) that returns the result of a die with sides equal to the num sides argument. From the main, call the roll die function 10,000 times (use a 6 sided die) and count the occurrence of the number of ls, 2s.3s, 55, and 6s. Print the number of times each number has occurred to the screen. (You can follow the example from the lecture slides. Example output of rolling a 6 sided die 10,000 times Num Is: 1666 Num 2s 1723 Num 6s: 1595 2. Write a program that contains a main function, a double custom operator function int op type. double x, double y), double min(double double), double max double x,double y), double pow(double x I) The main function is required to call the "custom operator function II) The custom opcrator function calls the "min, "max or pow function based on the value of the parameter op type (1-min).(2-max) (3pow) and returns the result of the called function. The arguments passed to the minmapow function z: the parameters x and y The "custom operator function" is required to return-1 if op type is not equal to 1, 2 or 3 III) Write your own min, max, and pow functions. Do not use the min, max, and pow functions from the math library 3. Write a Fib recursivel int n) function and a Fib iterative(int) function that computes the n-th Fibonacci number recursively and iteratively, respectivdly Next, compare the runtime of the two functions for reasonable values o n" and summarize your findings (you do not need to report the exact execution time for the programs) 4Write program that requests a number N from user, the main function then calls a recursive function print patterm(int) and passes N to it print pattem(int) prints the corresponding patterns hased on the value of N. Note that you should not use loop in the implementation N-2 N-3 N-4 5. Write a program with a main that calls a function void mycountO 20 times Create a global variable outside the main, a local variable in the function, and a static variable in the function. All the variables should be initialized to 0 when they are declared. Increment all the variables when the function "mycount" is called and print the value of each of the variables to the screen in each function call. In addition, print the values of the variables that are accessible from the main to screen at the end of the program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions