+ 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. 👏👏👏
5 Réponses
+ 20
increase row value(outer index) & decrease column value(inner index)
//can be done in 1 loop (run n times)☺
+ 1
https://code.sololearn.com/c12rZ1em9MO6/?ref=app
+ 1
Challenge to find out the diagonal value.
c++ with comments:
https://code.sololearn.com/ceFpep38hKRg/#cpp
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;
}