➽ Problem:-
https://www.hackerrank.com/challenges/diagonal-difference/problem
➽ Solution:-
#include<bits/stdc++.h>
using
namespace std;
int main()
{
int N;
cin>>N;
int A[N];
int LDS=0;
int RDS=0;
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
cin>>A[i];
if(i==j)
LDS += A[i];
if(i+j==N-1)
RDS += A[i];
}
}
cout << abs(LDS-RDS) << endl;
return 0;
}
0 Comments
Please do not enter any spam link in the comment section.