In: Computer Science
( 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:-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***