Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Diagonal Difference - O(n) .cpp #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions Diagonal Difference - O(n) .cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MAX 100
using namespace std;

int difference(int arr[][MAX], int n)
int difference(int arr[MAX][MAX], int n)
{
// Initialize sums of diagonals
int d1 = 0, d2 = 0;
Expand All @@ -13,22 +13,24 @@ int difference(int arr[][MAX], int n)
d2 += arr[i][n-i-1];
}


// Absolute difference of the sums
// across the diagonals
return abs(d1 - d2);
}

int main()
{
int n = 3;
int n ;//COnsidering Diagonals only for Square Matrix
cout<<"Enter the no.of columns";
cin>>n;

int arr[][MAX] =
{
{11, 2, 4},
{4 , 5, 6},
{10, 8, -12}
};
int arr[MAX][MAX];
for(int i=0 ;i<n;i++)
for(int j=0;j<n;j++)
cin>>arr[i][j];

cout <<"The Diffrence is"<<difference(arr, n);
return 0;

cout << difference(arr, n);
return 0;
}