Answer to Question #278131 in C++ for zain

Question #278131

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.


1
Expert's answer
2021-12-10T13:22:13-0500
#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;
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog