Knowee
Questions
Features
Study Tools

Write a program to print the quotient and remainder on dividing sum of left-top to right-bottom diagonal by sum of right-top to left-bottom diagonal.

Question

Write a program to print the quotient and remainder on dividing sum of left-top to right-bottom diagonal by sum of right-top to left-bottom diagonal.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python program that does that:

def diagonal_sum(matrix):
    # Initialize sums of diagonals
    d1 = d2 = 0
    n = len(matrix)

    for i in range(0, n):
        for j in range(0, n):
            # finding sum of primary diagonal
            if (i == j):
                d1 += matrix[i][j]

            # finding sum of secondary diagonal
            if (i == n - j - 1):
                d2 += matrix[i][j]

    # printing the result
    if d2 != 0:
        print("Quotient is", d1 // d2)
        print("Remainder is", d1 % d2)
    else:
        print("Cannot divide by zero")

# Test the function
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
diagonal_sum(matrix)

This program first calculates the sum of the elements in the left-top to right-bottom diagonal (primary diagonal) and the right-top to left-bottom diagonal (secondary diagonal) of the matrix. Then it prints the quotient and remainder of the division of the sum of the primary diagonal by the sum of the secondary diagonal. If the sum of the secondary diagonal is zero, it prints a message saying that division by zero is not possible.

This problem has been solved

Similar Questions

Write a C program that calculates the sum of both diagonals in a square matrix. Implement a function that takes a square matrix and its size as input and returns the sum of the main diagonal and anti-diagonal elements.Input3 31 2 3 4 5 6 7 8 9

Find the elements of the diagonal and the lower elements.Write a program to obtain a matrix and find the sum of the elements in the lower triangular matrix.Note: Only square matrixInput format :The first line of the input consists of the number of rows and columns.The second line of the input consists of the matrix element.Output format :The output prints the sum of the lower triangular matrix.Refer to the sample input and output for format specifications.Sample test cases :Input 1 :3 312 23 4556 78 8995 51 20Output 1 :312

Write a C Program to Compute the Sum of Diagonals of a square matrix. Print the sum of both diagonals separately. Get the number of rows and columns from the user.

Problem Statement:Accept two integers and print quotient  with 16 decimal places and print the remainder in next line.Input Format:Accept two integers as inputOutput Format:Print Quotient and Remainder as follows:The quotient when NUM1 is divided by NUM2 is QUOTIENT_VALThe remainder when NUM1 is divided by NUM2 is REM_VALConstraints:1<=N1,N2<=10^15Sample Input 1:54 65Sample Output 1:The quotient when 54 is divided by 65 is 0.8307692307692308The remainder when 54 is divided by 65 is 54Sample Input 2:23 78Sample Output 2:The quotient when 23 is divided by 78 is 0.2948717948717949The remainder when 23 is divided by 78 is 23

Alice is working on a program to calculate the quotient and remainder of the division of two integers. Write a program that utilizes the goto statement for control flow, If the remainder is zero, the program increments the quotient; otherwise, it decrements the quotient.Note: This question helps in clearing AMCAT exam.Input format :The first line of input consists of an integer n, representing the dividend.The second line of input consists of an integer n1, representing the divisor.Output format :The output displays the incremented or decremented value according to the remainder.If the remainder is non-zero, it decrements the quotient.If the remainder is zero, it increments the quotient.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:2 ≤ n ≤ 1501 ≤ n1 ≤ 15n ≥ n1

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.