Write a C program which reads the sensor temperature data and save the last 100 samples for each value in an array and calculate the average of 100 samples every 5 seconds displayed on serial monitor.
Thanks for the help in advance!
This is the code:
#include <stdio.h>
int main() {
int n, i;
float num[100], sum = 0.0, avg;
printf("Enter the last 100 temperature data: ");
scanf("%d", &n);
for (i = 0; i < n; ++i) {
printf("%d. temperature data: ", i + 1);
scanf("%f", &num[i]);
sum += num[i];
}
avg = sum / n;
printf("Average = %.2f", avg);
return 0;
}
Output:
Here as an Example I took 8 input but you can take 100 it will do same way.
Get Answers For Free
Most questions answered within 1 hours.