Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C :Write a program that produces a 10 × 4 table of random values. For thes

ID: 3902696 • Letter: U

Question

Using C :Write a program that produces a 10 × 4 table of random values. For these values, produce the arithmetic mean (i.e., the average) of the printed row values. Additional requirements specific to this assignment: 1. You cannot use arrays for this assignment. 2. For each of the 40 positions in the table, you should generate random values in the range of 0.0 to 99.99. You will only print those that are greater than or equal to 50.0. If the value produced is less than 50.0, fill its position in the table with spaces. 3. For each row, produce the average of the values printed, which won’t necessarily be all values generated. 4. It’s possible that none of the random integers produced for a particular line is greater than or equal to 50.0, which means that attempting to produce the average would require dividing by zero. When this happens, you should neither calculate nor print anything for the average of this line. 5. I used variables of type double for floating-point values; you should do the same to increase the likelihood of us getting the same averages. 6. The function rand() in stdlib.h produces pseudo-random integers greater than or equal to zero. You will need to use these values to produce values in the range of 0 to 99.99. So that we get the same values, use double value; value = (rand()%10000)/100.0;? 7. DO NOT seed the random number generator. While not seeding the random number generator would generally be a bad thing to do, I need to be able to easily determine if the output is correct. 8. When printing the output: (a) The values within each column should be aligned and right-justified. (b) The values should be printed to two decimal places and the decimal points within a column should be aligned. (c) Two blank spaces should be printed between each number in a row. (d) Use a vertical bar to separate the randomly generated values from their average.: 9. Don’t use global variables. 10. Your program must compile on omega.as a C89 program without warnings

Explanation / Answer

Screenshot

--------------------------------------------------

Program

//Header file for I/O and rand function
#include<stdio.h>
#include<stdlib.h>
//Main method
int main()
{
   //Variable for looping , average calculation , space and line seperation
   int i, j;
   double avg = 0, val;
   char str[] = " ";
   char line[] = "|";
   //Loop to display random values
   for (i = 0; i < 11; i++) {
       for (j = 0; j < 4; j++) {
           //Random value generation
           val = (rand() % 10000) / 100.0;
           //Average calculation sum
           avg = avg + val;
           //If value grater than 50 then only display
           if (val > 50) {
               printf("%4.2f",val);
               printf(" ");

           }
           //Otherwise space
           else {
               printf("%7s",str);
           }
          
       }
       //Line and average print
       avg = avg / 4;
       printf("%7s", line);
       printf("%4.2f",avg);
       //Each row seperation
       printf(" ");
   }
    return 0;
}

--------------------------------------------------------

Output

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote