Sunday, 2 April 2017

Hacker Rank Solution For " Diagonal Difference " in C++

Problem :- Diagonal Difference

Submit Your Solution Here :- Click Here

Copy The Code and paste it into hackerrank Editor .

Solution :-

#include <iostream>
using namespace std;

int main() {
    int N,lsum=0,rsum=0;
cin>>N;
    int a[N][N];

    for(int i=0;i<N;i++)
    {   
for(int j=0;j<N;j++)
{
cin>>a[i][j];
if(i==j)
{
lsum+=a[i][j];
}
}
}
for(int i=0;i<N;i++)
{
for(int j=N-1-i;j>=0;)
{
rsum+=a[i][j];
break;
       }
}
cout<<abs(lsum-rsum)<<endl;
return 0;
}



Output :-

Hacker Rank Solution For " Diagonal Difference " in C++

No comments:
Write comments

Recommended Posts × +