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

Submit the source code (your filename.c file) electronically and on paper as a h

ID: 3814550 • Letter: S

Question

Submit the source code (your filename.c file) electronically and on paper as a hard copy. Include copy of the results as comment lines in the completed program. All source code must be in a filename.c format. No other formats will be accepted Phase I General Preprocessing items Use emonic variables of 3 characters or more. Use void main (void) or void main in your program and leave off the return 0. Use double as the choice for all floating point values. Add heading items using as printf statement. Watch for instructions that specify a symbolic constant and assign that symbolic constant in all capital letters and using the #define. Thank you The "xxxx" or the (highlighted item) in a sample output will show examples of locations that the computer program will transfer values Phase II General procedures: A line of information in the program should be no longer than 80 characters. All user-defined function problems should include the student's last name as part of their function name. All user- defined function written for the class must have a prototype. The user-defined functions will be located in the program after the main program. Only use local variables in the programs, no global variables Problem #1 -Write a program that uses an array and reads up to 50 floating point values from the user and then calculates their average. In addition to calculating the average, the program will also compute the absolute deviation of each numerical quantity from the average using the formula deviation aluei average I, where i 1, 2 n The program should use loo The program will ask how many sets of numbers and ask how many numbers in each set. Since we are using a loop to perform the input and calculations, the quantity is variable up to 50 pieces of data. We just happen to give a certain amount of values the first time and a different amount of values are used the next time. The output display off numbers should be with 2 decimal places compared to the input of numbers. The shown input numbers have 1 decimal place. U of the Math header file built-in functions is mandatory where applicable in the program. Check your averages and deviations outside of the program to verify your output

Explanation / Answer

Answer:

#include<stdio.h>
#include<math.h>
void main()
{
   double num[50],sum,average,deviation;/*variable declaration*/
   int n,i,j,k,count;/*variable declaration*/
   printf("Sample Output Problem ");/*Displays the message*/
   printf("How many sets of numbers do you have?");/*Displays the message*/
   scanf("%d",&n); /*Reads the value from the keyboard and puts in the variable n*/
   for(i=1;i<=n;i++)/*Outer loop is meant for number of sets*/   
   {
       for(k=1;k<=50;k++)/*This loop is to make all the array elements to 0*/
       num[k]=0;
       printf(" How many numbers will be averaged in set %d ?=>",i);
       scanf("%d",&count);/*reads number of numbers in the i'th set and puts in the variable 'count'*/
       printf(" Values in set# %d ",i);
       for(j=1;j<=count;j++)/*This loop is meant for taking the values into the array in i'th set*/
       {
           printf("input# %d--> value=",j);
           scanf("%lf",&num[j]);
       }
       sum=0,average=0;/*In every iteration the initial values of sum, and average should be zero*/
       for(j=1;j<=count;j++)/*In this loop it calculates the sum*/
           sum=sum+num[j];
       average=(double)sum/count;/*Calculating the average*/
       printf(" The average is %.2lf",average);
       for(j=1;j<=count;j++)/*In this loop it calculates the deviation of each and every entry of the array*/
       {
           deviation=fabs(num[j]-average);/*fabs() is to avoid the negative values, the corresponding header file is math.h*/
           printf(" item# %d value= %.2lf deviation= %.2lf",j,num[j],deviation);/*%.2lf is for displaying two digits after the decimal point*/
   }
}
getch();
}