Question

In: Computer Science

( C language only and all values should be float )Generate a function called randomnum(n,m,neg); where...

( C language only and all values should be float )Generate a function called randomnum(n,m,neg); where n and m are the lower and upper bounds for the random number; the generated number is negative if a variable named neg is true .These numbers should be non-zero with a maximum absolute value of 15 . You must use bitwise arithmetic to calculate the modulus of the random number

Solutions

Expert Solution

Solutions:-As you mentioned .I did that program in C Language...i have atached all screnshot of that program with output.

TextCode:-

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h> //Include if you want to pass neg value
#include<time.h> //Generating random numbers

int randomnum(int n,int m,bool neg){
  
srand(time(0)); // Maintain unique numbers generated
  
int num = rand()%(m-n+1)+n; // Generating a random number within (n,m)
if(num>15)return 0; // if greater than 15, return nothing
if(neg==true){ // If neg is true, return the negative of the number
return -1*num;
}else{
return num;
}
return 0;
}
// Driver code(main)
int main(){
// generate two random numbers
int b = randomnum(5,10,false);
int c = randomnum(1,5,true);
  
int res = b & c; // apply bitwise & to calculate the modulus

float k=(float)c; //convert in float value
printf("Random number generated in float value : %f",k); //print the value.
}

OUTPUT:-

NOTE:-I HOPE YOUR ARE HAPPY WITH MY ANSWER PLEASE DO UPVOTE...
IF YOU HAVE ANY QUERY THEN COMMENT ME ..
***THANK YOU***


Related Solutions

( C language only )Generate a function  called randomnum(n,m,neg); where n and m are the lower and...
( C language only )Generate a function  called randomnum(n,m,neg); where n and m are the lower and upper bounds for the random number; the generated number is negative if a variable named neg is true .These numbers should be non-zero with a maximum absolute value of 15 . You must use bitwise arithmetic to calculate the modulus of the random numbers
(C++ only please) Write a function called maximum that takes an array of double values as...
(C++ only please) Write a function called maximum that takes an array of double values as a parameter and returns the largest value in the array. The length of the array will also be passed as a parameter. (Note that the contents of the array should NOT be modified.) Write a function called printReverse that takes an array of characters and the length of the array as parameters. It should print the elements of the array in reverse order. The...
C PROGRAMMING 1. Write a C Language inline function that computes the cube of float X,...
C PROGRAMMING 1. Write a C Language inline function that computes the cube of float X, if X is greater than 1 and X is less than 100. Put the inline function in a main program that reads X from the keyboard, calls the function, and then outputs the result. 2. Show an empty statement and detail what it does? 3. A collection of predefined functions is called a Database                    C) Subroutine                       E) None of these Library                       D) Directive 4....
In C language: Write a function which can receive a float array, an integer number(number of...
In C language: Write a function which can receive a float array, an integer number(number of elements) as input arguments and print all the elements in the array with 2 decimal precision.
Programming in C language (not C++) Write a runction derinition for a function called SmallNumbers that...
Programming in C language (not C++) Write a runction derinition for a function called SmallNumbers that will use a while loop. The function will prompt the user to enter integers ine by one, until the user enters a negative value to stop. The function will display any integer that is less than 25. Declare and initialize any variables needed. The function takes no arguments and has a void return type.
Question 1 a) Determine whether the language {a n b m c n | n >...
Question 1 a) Determine whether the language {a n b m c n | n > 0} is regular or not using pumping Lemma. b) Prove that the language {(ai bn | i, n > 0, i = n or i = 2n} is not regular using the Pumping Lemma.
In C language: Write the fnFindMin function which can receive a float array, an integer number(number...
In C language: Write the fnFindMin function which can receive a float array, an integer number(number of elements) as input arguments and finds the minimum value in the array. This function should return the array index (subscript) of the minimum value.
C program only There is a documented prototype for a function called get_a_line in the .c...
C program only There is a documented prototype for a function called get_a_line in the .c file. Write a definition for get_a_line—the only function called from that definition should be fgetc. You can use the given main function to test your code. You should run the executable several times to check different cases: Type Ctrl-D in response to the prompt for input. get_a_line should fail to read any characters, put a ’\0’ character at the beginning of the array, and...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an array. Print all unique elements of an array Enter the number of elements to be stored in the array: 4 Input 4 elements in the arrangement: element [0]: 3 element [1]: 2 element [2]: 2 element [3]: 5 Expected output: The only items found in the array are: 3 5
Programming in C language (not C++) Write a function definition called PhoneType that takes one character...
Programming in C language (not C++) Write a function definition called PhoneType that takes one character argument/ parameter called "phone" and returns a double. When the variable argument phone contains the caracter a or A, print the word Apple and return 1099.99. When phone contains the caracter s or S print the word Samsung and return 999.99. When phone contains anything else, return 0.0.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT