In: Computer Science
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 to apply the if-condition for all
50 numbers.
b.Determine the probability of the chosen number being
greater than or equal to 150
and less than 250?
c.Display the output using the serial monitor of
Arduino.
Code
void setup() {
Serial.begin(9600);
}
void loop() {
int min=100;
int max=300;
int num,count=0;
for(int i=0;i<50;i++)
{
num=random(min,max);
if(num>200)
{
count++;
}
}
float prob=count/50.00;
Serial.print("Probability that number is greater than 200 out pof
50 random number is : ");
Serial.println(prob);
delay(500);
}
outptu
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.