Question

Complete the implementation of the array_stats function. This activity will help you learn how to use counter controlled loop• Test plan: Test your program with several input sequences. Your test plan should include the following categories: . An empNotes: • A program similar to your produces the output sequences pictured below. The images illustrate a convenient way to in

Item mean : 9.111111 Item min : 1.333333 Item max 14.000000 The second image shows a run with a large input file, but the lis• Use this test driver to implement and test your function prior to submission #include <stdio.h> #include <stdlib.h> #includ

Use the C programming language to complete

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

// Declare Global variables here.

void array_stats() {
// Insert your solution here.
}

#include <stdlib.h>
#include <time.h>

int main() {
// Simulate the test setup process.
srand( time( NULL ) );
for ( int i = 0; i < 32; i++ ) {
val[i] = rand();
}
val_count = rand();
val_mean = rand();
val_min = rand();
val_max = rand();

// Call submitted code.
array_stats();

// Display contents of array val.
for (int i = 0; i < val_count; i++) {
printf("%f ", val[i]);
}

printf("\n");
printf("Item count: %d\n", val_count);
printf("Item mean : %f\n", val_mean);
printf("Item min : %f\n", val_min);
printf("Item max : %f\n", val_max);

return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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


double val[32];
int val_count=0;
double val_mean=0.000000;
double val_min=0.000000;
double val_max=0.000000;


void array_stats() {
int i;

   val_min=val[0];
for(i=0;i<32;i++)
{   
if(i<32)
{
val_mean=val_mean+val[i];
}
if(val[i]<val_min)
val_min=val[i];
if(val[i]>val_max)
val_max=val[i];

val_count++;
}
  
if(val_count>32)
val_mean=val_mean/32;
else
val_mean=val_mean/val_count;
  
}

#include <stdlib.h>
#include <time.h>

int main() {
  
srand( time( NULL ) );
int i;
for ( i = 0; i <32 ; i++ ) {
val[i] = rand();
}


// Call submitted code.
array_stats();

// Display contents of array val.

for ( i = 0; i < val_count; i++) {
printf("%f ", val[i]);
}
  
printf("\n");
printf("Item count: %d\n", val_count);
printf("Item mean : %f\n", val_mean);
printf("Item min : %f\n", val_min);
printf("Item max : %f\n", val_max);

return 0;
}

Add a comment
Know the answer?
Add Answer to:
Use the C programming language to complete #include <stdio.h> #include <stdlib.h> #include <float.h> // Declare Global...
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
  • C PROGRAMMING #include <stdio.h> #include <stdlib.h> struct nodet { int data; struct nodet *link; }; struct...

    C PROGRAMMING #include <stdio.h> #include <stdlib.h> struct nodet { int data; struct nodet *link; }; struct nodet *makeAnode(int val) { struct nodet *box; box = malloc(sizeof(struct nodet) ); box->data = val; box->link = NULL; return box; } void printList(struct nodet *L) { struct nodet = *mov; mov = L; while(mov != NULL) { printf("%d ", mov->data); mov = mov->link; } printf("\n"); } // THIS SHOULD COUNT HOW MANY ITEMS (NODES) ARE IN THE LIST. int listLen(struct nodet **L) { int...

  • Complete the program below in C please #include <stdio.h> #inlcude <stdlib.h> #include <time.h> typedef struct {...

    Complete the program below in C please #include <stdio.h> #inlcude <stdlib.h> #include <time.h> typedef struct { int points; int strength; } Hero; /* print out the hero given by the parameter */ void printHero( ... ) { . . } void main() { Hero heroA, heroB; /* initialize both heroes to your choice of values */ . /* Pick one hero using rand(). Print out that hero */ . }

  • How would I change the following C code to implement the following functions: CODE: #include <stdio.h>...

    How would I change the following C code to implement the following functions: CODE: #include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { if (argc != 2) printf("Invalid input!\n"); else { FILE * f = fopen (argv[1], "r"); if (f != NULL) { printf("File opened successfully.\n"); char line[256]; while (fgets(line, sizeof(line), f)) { printf("%s", line); } fclose(f); } else { printf("File cannot be opened!"); } } return 0; } QUESTION: Add a function that uses fscanf like this:...

  • can someone help me with changing this to c++ language #include <stdlib.h> #include <stdio.h> #include <pthread.h>...

    can someone help me with changing this to c++ language #include <stdlib.h> #include <stdio.h> #include <pthread.h> #include <string.h> #include <dirent.h> #include <sys/wait.h> #include <time.h> #include <sys/stat.h> #include <unistd.h> char *pathLog; char *pathRep;    struct stat attr; int fileNum, curNum; char *create_logPath(char *directory);    void *funcChecker(void *pathSub); void *funcprintTimeAndChanges(void *pathSub);    void main(int argc, char *argv[]) {    if(argc < 3)    { printf("%s must be executed with exactly two additional arguments (pathRep, pathSub)!\n", argv[0]); printf("Typed count is %d\n", argc); printf("Aborted...

  • sort.c #include <stdlib.h> #include <stdio.h> #include "libsort.h" int main() {     int* array;     int size,...

    sort.c #include <stdlib.h> #include <stdio.h> #include "libsort.h" int main() {     int* array;     int size, c;     float median;     printf("Enter the array size:\n");     scanf("%d", &size);     array = (int*) malloc(size * sizeof(int));     printf("Enter %d integers:\n", size);     for (c = 0; c < size; c++)         scanf("%d", &array[c]);     sort(array, size);     printf("Array sorted in ascending order:\n");     for (c = 0; c < size; c++)         printf("%d ", array[c]);     printf("\n");     median = find_median(array,...

  • use only #include<stdio.h> #include <stdlib.h> In C Program. Using at least 3 different types/pieces of information,...

    use only #include<stdio.h> #include <stdlib.h> In C Program. Using at least 3 different types/pieces of information, define an appropriate self-referential structure and manage the selected data using a linked list. A data item should have a unique identifier. Use a (case selection structure) to control the user selection from the following menu: 1) Store / Insert a data item in order 2) Remove a specific data item from the list 3) View a specific data item 4) Print a list...

  • #include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate...

    #include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate a random number. Then it has to declare how many tries the user has for the game loop. we then need the player to enter their guess. After every guess we have to give an output of how many numbers they have in the right location and how many they have the right number. The player will keep guessing until their 10 tries are...

  • Question 1 In the following incomplete C program: #include stdlib.h> #include <stdio.h> int main () { int i, n, max; int array[100]; ... } return 0; } an array of random int values is populat...

    Question 1 In the following incomplete C program: #include stdlib.h> #include <stdio.h> int main () { int i, n, max; int array[100]; ... } return 0; } an array of random int values is populated with n random values. Write only the code to find the location of the maximum value in the array. Question 2 Follow these instructions in your Linux account: 1. Create a file called data.txt in the root folder in your account. 2. Create a new...

  • #include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str);...

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str); int numUppltr(char *str); int numLwrltr(char *str); int punChar(char *str); char*readString(char *str); int main() { char givString[MAX_LEN]; puts("Enter your string(Max 255 characters):"); //readString(givString); gets(givString); printf("\nnumber of words :%d",numWords(givString)); printf("\nnumber of uppercase letters %d",numUppltr(givString)); printf("\nnumber of lowercase letters %d",numLwrltr(givString)); printf("\nnumber of punctuations %d\n",punChar(givString)); printf("\nnumber of digits:%d\n",numDigit(givString)); system("pause"); return 0; } char *readString(char *str) { int ch, i=0; while((ch=getchar())!=EOF && ch!='\n') { if(i) { str[i]=ch; i++; }...

  • Please fill in the code to reverse a linked list. IN C++ #include <stdio.h> #include <stdlib.h>...

    Please fill in the code to reverse a linked list. IN C++ #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list...

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