Please write in programing c Thank you! Question 2: Running Average I\'m studyin
ID: 3589696 • Letter: P
Question
Please write in programing c Thank you!
Question 2: Running Average
I'm studying tempertures over various time scales. Unfortunately, my thermometer isn't very precise, so I need to average its readings together to level out the spikes.
I need you to write a program to generate a running average of my temperture data. The first (integer) input is the number of data points (guaranteed to be less than 1000). The next (integer) is the number of data points to be averaging together. The rest of the input are whitespace separated floats. Please output the running average with one point of precision, each on their own line.
Example Input
10 4
27.9 31.7 29.56 35.7 38.5 41.6 50.6 48.6 55.7 60.4
Question 3: Remove Outliers
Example input
Correct output
Question 4: Grading the top ten scores
I'm running an experiment on telepathy. Partners in the experiment try to mentally transmit numbers from one partner to the other. The numbers are integers in the range 0-100 inclusive. I gave one partner (sender) a list of numbers to transmit, and the other partner (receiver) wrote down the number they "recieved". I'm interested in the average absolute different between those two lists.
For input, the first number will be the number of numbers transmitted (less than 1000). The next set of numbers are the numbers that the sender sent, and then the numbers received. Report the average absolute difference between the sender and receiver (one decimal point of precision).
Example Input:
Correct Output:
Explanation / Answer
Question 2: Running Average
#include<stdio.h>
#include<float.h>
#include<stdlib.h>
int main(){
int n, i=0,j,k=1, p;
float *a, avg= 0;
scanf("%d %d", &n, &p);
a = (float*)malloc(n * sizeof(float));
for(j=0;j<n;j++)
scanf("%f", &a[j]);
printf("Data points Average of %d ", p);
while(n--){
printf("%.1f ",a[i]);
avg = avg + a[i];
j = i+1;
if (j%p == 0){
avg = avg / p;
printf(" %.1f ",avg);
avg = 0;
}
i++;
}
}
Question 3: Remove Outliers
#include<math.h>
#include<stdio.h>
#include<float.h>
#include<stdlib.h>
int main(){
int n, i=0,j,k=1, p;
float *a, avg= 0, temp=0, outlier, diff;
scanf("%d", &n);
a = (float*)malloc(n * sizeof(float));
for(j=0;j<n;j++)
scanf("%f", &a[j]);
for(i=0;i<n;i++){
avg = avg + a[i];
}
avg = avg /n;
temp = 0;
for(i=0;i<n;i++){
diff = a[i] - avg;
diff = abs(diff);
if (diff > temp){
temp = diff;
outlier = a[i];
}
}
// printf("Outlier is:- %.1f ", outlier);
for(i=0;i<n;i++){
if(a[i]==outlier)
continue;
printf("%.1f ", a[i]);
}
}
Question 4: Grading the top ten scores
#include<math.h>
#include<stdio.h>
#include<float.h>
#include<stdlib.h>
int main(){
int n, i=0,j,k=1, p;
float *a, *b, avg= 0, diff;
scanf("%d", &n);
a = (float*)malloc(n * sizeof(float));
b = (float*)malloc(n * sizeof(float));
for(j=0;j<n;j++)
scanf("%f", &a[j]);
for(j=0;j<n;j++)
scanf("%f", &b[j]);
for(i=0;i<n;i++){
diff = a[i] - b[i];
diff = abs(diff);
avg = avg + diff;
}
avg = avg / n;
printf("%.1f", avg);
}