Data collected by sensor devices may contain noise and need smoothing. One simple approach to smooth out data is to replace each value with the average of the value and its two neighboring values (or one neighboring value if it is at either end of the array). Write a program that inputs 4*3 array of integers and smooth out the values. You should not create another array in your solution. Also, you will use all neighbors to for smoothing. For example, for smoothing Red cell, you will use values of all orange cells. You will use updated value of cells for smoothing.
#include<iostream>
using namespace std;
int main(){
int arr[4][3];
cout<<"Enter the elements of the array:\n";
for(int i=0; i<4; i++){
for(int j=0; j<3; j++){
cin>>arr[i][j];
}
}
int sum = 0;
for(int i=0; i<4; i++){
for(int j=0; j<3; j++){
sum += arr[i][j];
}
}
int average = sum /12;
for(int i=0; i<4; i++){
for(int j=0; j<3; j++){
arr[i][j] = average;
}
}
}
Comments
Leave a comment