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

Question 1: Small experiment to see how C organizes arrays in memory. Write a pr

ID: 3608846 • Letter: Q

Question

 Question 1:
Small experiment to see how C organizes arrays in memory.

Write a program that initializes three arrays, each location being the zero value:

- an array of 10 ints
- an array of 5 floats
- an array of 20 chars


Question 2:


Part 1: Write a function that has the following interface:

double average (int size, double values []);
The function should return the average of the first size values in the array values.

Part 2: Write a function that has the following interface:

double promptForData (int index);
The function should read a double precision floating point number from the console after printing: "Enter item %d : ". Where %d is the index number.

Part 3: Write a program that asks for a number of numbers to be input. Read up to that number, but no more than 50, double precision floating point numbers into an array. After each number is input, print a running average, calculated with the average() function described above. If the average is the last average to be displayed, indicate it is the final average.



Examples:

Enter number of values to be input : 5
Enter item 1 : 22.3
Current average is 22.3.
Enter item 2 : 54.2
Current average is 38.25.
Enter item 3 : 74
Current average is 50.1667.
Enter item 4 : 83.1
Current average is 58.4.
Enter item 5 : -90.
Final average is 28.72.
Number of values : 500
Too many values, only reading first 50.
Enter item 1 : 0.9
Current average is 0.9.
Enter item 2 : 1.8
Current average is 1.35.
...
Enter item 50: 92.3
Final average is 50.0.
Enter number of values to be input : -234
Final average is 0.

Explanation / Answer

//don't forget to rateit.
1.

#include<stdio.h> intmain() { intarr_int[10]; floatarr_float[5]; chararr_char[20]; inti;
for(i=0;i<10;i++) arr_int[i]=0; for(i=0;i<5;i++) arr_float[i]=0;
for(i=0;i<20;i++) arr_char[i]=0; system("pause"); }
2.


#include<stdio.h>    double average (int size, double values[])    {    double avg=0;    int i;    for(i=0;i<size;i++)    avg+= values[i];        avg = avg/size;    return avg;    }    double promptForData (int index)    {     double d;    printf(" Enter item %d : ",index);    scanf("%lf",&d);    d = d * 100;    d = (int) d;    d = d/100;
   return d;    } intmain() {    int num,i;    double arr[50];    printf("Enter number of values to be input:");    scanf("%d",&num);    if(num>50)    {    printf("Too many values, only reading first50.");    num=50;    }    for(i=0;i<num;i++)    {    arr[i] = promptForData(i);    printf("Current average is:%.2lf",average(i+1,arr));        }    printf(" ");    system("pause"); } #include<stdio.h> intmain() { intarr_int[10]; floatarr_float[5]; chararr_char[20]; inti;
for(i=0;i<10;i++) arr_int[i]=0; for(i=0;i<5;i++) arr_float[i]=0;
for(i=0;i<20;i++) arr_char[i]=0; system("pause"); }
2.


#include<stdio.h>    double average (int size, double values[])    {    double avg=0;    int i;    for(i=0;i<size;i++)    avg+= values[i];        avg = avg/size;    return avg;    }    double promptForData (int index)    {     double d;    printf(" Enter item %d : ",index);    scanf("%lf",&d);    d = d * 100;    d = (int) d;    d = d/100;
   return d;    } intmain() {    int num,i;    double arr[50];    printf("Enter number of values to be input:");    scanf("%d",&num);    if(num>50)    {    printf("Too many values, only reading first50.");    num=50;    }    for(i=0;i<num;i++)    {    arr[i] = promptForData(i);    printf("Current average is:%.2lf",average(i+1,arr));        }    printf(" ");    system("pause"); }

#include<stdio.h>    double average (int size, double values[])    {    double avg=0;    int i;    for(i=0;i<size;i++)    avg+= values[i];        avg = avg/size;    return avg;    }    double promptForData (int index)    {     double d;    printf(" Enter item %d : ",index);    scanf("%lf",&d);    d = d * 100;    d = (int) d;    d = d/100;
   return d;    } intmain() {    int num,i;    double arr[50];    printf("Enter number of values to be input:");    scanf("%d",&num);    if(num>50)    {    printf("Too many values, only reading first50.");    num=50;    }    for(i=0;i<num;i++)    {    arr[i] = promptForData(i);    printf("Current average is:%.2lf",average(i+1,arr));        }    printf(" ");    system("pause"); } #include<stdio.h>    double average (int size, double values[])    {    double avg=0;    int i;    for(i=0;i<size;i++)    avg+= values[i];        avg = avg/size;    return avg;    }    double promptForData (int index)    {     double d;    printf(" Enter item %d : ",index);    scanf("%lf",&d);    d = d * 100;    d = (int) d;    d = d/100;
   return d;    } intmain() {    int num,i;    double arr[50];    printf("Enter number of values to be input:");    scanf("%d",&num);    if(num>50)    {    printf("Too many values, only reading first50.");    num=50;    }    for(i=0;i<num;i++)    {    arr[i] = promptForData(i);    printf("Current average is:%.2lf",average(i+1,arr));        }    printf(" ");    system("pause"); }
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