Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

NxN Array

# A simple Python program to
# find sum of diagonals
MAX = 100
 
def printDiagonalSums(mat, n):
 
    principal = 0
    secondary = 0;
    for i in range(0, n):
        for j in range(0, n):
 
            # Condition for principal diagonal
            if (i == j):
                principal += mat[i][j]
 
            # Condition for secondary diagonal
            if ((i + j) == (n - 1)):
                secondary += mat[i][j]
         
    print("Principal Diagonal:", principal)
    print("Secondary Diagonal:", secondary)
 
# Driver code
a = [[ 1, 2, 3, 4 ],
     [ 5, 6, 7, 8 ],
     [ 1, 2, 3, 4 ],
      [ 5, 6, 7, 8 ]]
printDiagonalSums(a, 4)
 
# This code is contributed
# by ihritik
Comment

PREVIOUS NEXT
Code Example
Python :: using python script in C# interface 
Python :: line of best fit in linear regression 
Python :: non linear regression 
Python :: bee swarm plot 
Python :: put legend in subplot 
Python :: Generate bootstrap replicate of 1D data that return a particular operation 
Python :: python synta error 
Python :: Python RegEx Escape – re.escape() Syntax 
Python :: why do we write f before double quotes in print statement in python 
Python :: 0 
Python :: how to open local software using python 
Python :: visualising centroid of an unsupervised learning algorithm 
Python :: words repeating in word cloud python 
Python :: Creating a bag-of-words in scikit-learn 
Python :: rpi pip3 installieren 
Python :: Read a string with digits from the input and convert each number to an integer. Create a list in which you should include only odd digits. 
Python :: subprocess readline blocking problem 
Python :: looping through models and plotting their performance 
Python :: how to have unlimited parameters in a function in python 
Python :: Python 0 evaluates to False 
Python :: django Account has no customer 
Python :: python nc group variables 
Python :: what is sklearn.base 
Python :: automation script for paytm coupon 
Python :: python get text between two points 
Python :: python output parameter 
Python :: using -h on python file 
Python :: name decorator in python 
Python :: FilePathField 
Python :: django voice lib 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =