Question
Use VI and post output screen
Use a For Loop to generate 100 random numbers. Determine the most current maximum and minimum number as the random numbers are being generated. This is sometimes referred to as a running maximum and minimum. Display the running maximum and minimum values as well as the current random num- ber on the front panel. P5.2 Be sure to include the Time Delay Express VI so the user is able to watch the values update as the For Loop executes. Figure P5.2 shows the Time Delay Express VI configuration dialog box (accessed by double-clicking on the VI) with a recommended delay of 0.1 second. Double-click on Express Vi Set Time delay D Configure Timp Oelay (Time Delay] 23 |ー. →| Time delay(seconds) 0.100 Tirne Delay OK Cancel Help FIGURE P5.2 Time Delay Express VI with configuration dialog box showing 0.1 second delay Place the Time Delay Express VI within the For Loop.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/* Purpose : To find the minimum and maximum of 100 random numbers generated.*/

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int minimum; //variable to store the maximum of the generated random numbers.
int maximum; //variable to store the minimum of the generated random numbers.
int number; // variable to store every number generated by the rand function.
int i; //variable to keep iteration count.
int initNum; //variable to store the first number generated by the rand function.
initNum = rand(); //generate the first random number.
printf("\nNumber 1 = %d", initNum); // Print the first random number generated.
minimum = initNum; // initNum is assumed to be both the minimum and maximum to begin with.
maximum = initNum; // initNum is assumed to be both the minimum and maximum to begin with.
for(i = 2;i<=100;i++) { //starting the iteration from 2 as already 1 number is read.
number = rand(); //generation of random numbers using rand function.
sleep(1); // delays the generation by 1 second for user to observe
printf("\nNumber %d = %d",i, number); // prints the numbers generated by the rand function
  
if(maximum < number) //logic to find max, checks with the next number to see if
maximum = number; //current max is less than the next generated number, if so swap
if(minimum > number) //logic to find min, checks with the next number to see if
minimum = number; //current min is more than the next generated number, if so swap
}
printf("\n Minimum = %d", minimum); // print the minimum
printf("\n Maximum = %d", maximum); // print the maximum
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Use VI and post output screen Use a For Loop to generate 100 random numbers. Determine...
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
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
ADVERTISEMENT