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"<