+ 7

✌Challenge to find out diagonal value 👍

Suppose you have given the size(Row=Column=Size) and elements of a Matrix. You have to find out the total adding the diagonal value. Example: size : 3 elements : 1 2 3 4 5 6 7 8 9 Answer : 7 + 5 + 3 = 15 Use any language & try to explain. 👏👏👏

26th Jan 2018, 12:18 PM
Pranta Saha
Pranta Saha - avatar
7 Answers
+ 20
increase row value(outer index) & decrease column value(inner index) //can be done in 1 loop (run n times)â˜ș
26th Jan 2018, 12:56 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
https://code.sololearn.com/c12rZ1em9MO6/?ref=app
26th Jan 2018, 2:15 PM
Arun
+ 1
Challenge to find out the diagonal value. c++ with comments: https://code.sololearn.com/ceFpep38hKRg/#cpp
27th Jul 2018, 4:26 PM
Tim Myers
Tim Myers - avatar
0
#include <iostream> using namespace std; int main() { int n; cin>>n; int a=0; int sum=0; int p=n*n; for(int i=1;i<=p;i++) { cout<<i<<" "; if(i%n==0){ cout<<endl; sum=sum+i-a; a++; } cout<<sum; }
26th Jan 2018, 2:17 PM
Arun