Header Ads

The average of the non-boundary elements of 2D array

 



Solved : 

/The average of non-boundary elements of 2D array.

#include<iostream>

using namespace std;

int main( )

{

     int Addition=0;

   int arr[5][5] ={

        { 1, 2, 3,4,5},

        { 6, 7, 8,9,10},

        { 11,12,13,14,15},

        { 1, 2, 3,4,5},

        { 6, 7, 8,9,10}

   };

  cout<<"The 2D Array is:"<<endl;

    for(int i=0;i<5;i++)//indicate the row that how much row you will take

    {

        for(int j=0;j<5;j++)

        {

            cout<<"\t"<<arr[i][j];

        }

        cout<<endl;

    }

    cout<<"First custom:"<<endl;

    for(int i=0;i<4;i++)

    {

        for(int j=0;j<4;j++)

        {

            cout<<"\t"<<arr[i][j];

        }

     cout<<endl;

    }

cout<<"The non-boundary array element is:"<<endl;

    for(int i=1;i<4;i++)

    {

        for(int j=1;j<4;j++)

        {

            cout<<"\t"<<arr[i][j];

        }

cout<<endl;

    }

    cout<<"Summation of non-boundary element is:"<<" ";

    for(int i=1; i<4; i++)

    {

         for(int j=1;j<4;j++)

        {

            Addition+=arr[i][j];

        }

    }

    cout<<Addition<<endl;

    cout<<"The average of the non-boundary elements is:"<<" "<<Addition/3<<endl;


}

Output:




No comments

Powered by Blogger.