From b86de9f0687f0f30d01139d3e440fa01739d288f Mon Sep 17 00:00:00 2001 From: SangeethaPrabhu2021 <86423721+SangeethaPrabhu2021@users.noreply.github.com> Date: Sat, 16 Oct 2021 09:34:40 +0530 Subject: [PATCH] Update Diagonal Difference - O(n) .cpp Removed Initialization and inputed the elements if the array from the user! --- Diagonal Difference - O(n) .cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Diagonal Difference - O(n) .cpp b/Diagonal Difference - O(n) .cpp index 28bde52..48fae44 100644 --- a/Diagonal Difference - O(n) .cpp +++ b/Diagonal Difference - O(n) .cpp @@ -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; @@ -13,6 +13,7 @@ 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); @@ -20,15 +21,16 @@ int difference(int arr[][MAX], int n) 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>arr[i][j]; + + cout <<"The Diffrence is"<