Question

C Language : int getRandomNumber( int min, int max ) Write a function that computes a...

C Language :

int getRandomNumber( int min, int max )

Write a function that computes a random number between min and max, inclusive, and returns it.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<time.h>
int getRandomNumber( int min, int max )
{
srand(time(0));
int num=(rand() % (max + 1 - min)) + min;
return num;

}
int main()
{
int min,max;
printf("Enter minimum range: ");
scanf("%d",&min);
printf("Enter Maximum range: ");
scanf("%d",&max);
int num=getRandomNumber(min,max);

printf("random number is: %d", num);
}

Add a comment
Know the answer?
Add Answer to:
C Language : int getRandomNumber( int min, int max ) Write a function that computes a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • help me solving this both please in c++ language 6 Write function max(int al Lint n)...

    help me solving this both please in c++ language 6 Write function max(int al Lint n) that receives an array of integer and its length, it returns the maximum number in that array. Test your function in main. 7) Write functin reverse (char x[ .int n) that reieves an array of characters and reverse the order of its elements. Test this function in main.

  • write a c++ function, do not #include anything, that returns the max of 6 ints int...

    write a c++ function, do not #include anything, that returns the max of 6 ints int max(int, int, int, int, int, int); allowed to use built in max(int, int) function.

  • 3.a The function is named validity(). It receives 2 floating point parameters, min and max, from...

    3.a The function is named validity(). It receives 2 floating point parameters, min and max, from the program that invoked it. The function asks the user to enter a float number. Using a while loop it checks whether the number is valid (between min and max, inclusive) If not valid, the while loop uses this statement to prompt for a new number: num = float (input (" Enter a number that is at least :"+ str(min) + "and at most:...

  • Write four overloaded methods called randomize. Each method will return a random number based on the...

    Write four overloaded methods called randomize. Each method will return a random number based on the parameters that it receives: randomize() - Returns a random int between min and max inclusive. Must have two int parameters. randomize() - Returns a random int between 0 and max inclusive. Must have one int parameter. randomize() - Returns a random double between min and max. Must have two double parameters. randomize() - Returns a random double between 0 and max. Must have one...

  • in ml language or sml Exercise 14 Write a function maxpairs of type (int * int)...

    in ml language or sml Exercise 14 Write a function maxpairs of type (int * int) list -> int lise that takes a list of pairs of integers and returns the list of the max elements from each pair. For example, if you evaluate maxpairs ((1,3), (4,2), (-3,-4)] you should get [3,4,-3).

  • c language not c++ c language int mininum(int a[135) int i; int min. Question 2 (4...

    c language not c++ c language int mininum(int a[135) int i; int min. Question 2 (4 points) If ptr is an integer pointer and x in an integer variable then write one statement to set ptr to point to x then write another statement to increment x by 10 using ptr (not using x) (4 points) Question 3 (4 points) Saved

  • Problem 5 Given a list a, the max function in Python's standard library computes the largest...

    Problem 5 Given a list a, the max function in Python's standard library computes the largest element in a: max(a) . Similarly, min(a) returns the smallest element in a . Write your own my_max and my_min functions. In [ ]: # YOUR CODE HERE raise Not ImplementedError() In [ ]: # YOUR CODE HERE raise Not ImplementedError() In [ ]: a = [0.28197719, 0.59580708, 0.54095388, 0.44264927, 0.12360858, 0.3067179, 0.33002426, 0.43553806, 0.14259775, 0.01909447] assert_equal(my_max(a), max(a)) assert_equal(my_min(a), min(a))

  • PART B Write the following three methods: public int GetRandemniform(int min, int max) This method returns...

    PART B Write the following three methods: public int GetRandemniform(int min, int max) This method returns a random number from a uniform distribution between in and are public double GetRandom Normal double mean, double sidder) This method returns aandom number from a normal distribution with a mean of mean and standard deviation of public int Getininden double mini, double mari, int numbins, double valutahin) This method returns the Bin Index given an input minimum of input maximum of his number...

  • Write a C program, containing the following functions. Function int recursive_fibonacci(int n) computes and returns the...

    Write a C program, containing the following functions. Function int recursive_fibonacci(int n) computes and returns the nth F(n) using recursive algorithm (i.e., recursive function call). Fibonacci numbers are defined by F(1)=F(2)=1, F(i) = F(i-1)+F(i-2), i=2,… . Function int iterative_fibonacci(int n) computes and returns the nth Fibonacci number F(n) using iterative algorithm (i.e., loop). The main function measures the memory usage and run time of iterative_fibonacci(40) and recursive_fibonacci(40), and does the comparison. To capture the execution time by millisecond, it needs...

  • C++ language Write a function, int flip(string a[], int n); It reverses the order of the...

    C++ language Write a function, int flip(string a[], int n); It reverses the order of the elements of the array and returns n. The variable n will be greater than or equal to zero. Example: string array[6] = { "a", "b", "", "c", "d", "e" }; int q = flip(array, 4); // returns 4 // array now contains: "C" "" "" "a" "d" "e" O Full Screen 1 code.cpp + New #include <string> 2 using namespace std; 3 4- int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT