📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    Complete the Python code to print the elements of the

    main diagonal of a square matrix matrix of size N x N. def print_main_diagonal(matrix, N):     for i in range(N):         _________ # Line to complete
    A print(matrix[i][N - 1 - i]) Correct Answer Incorrect Answer
    B print(matrix[i][0]) Correct Answer Incorrect Answer
    C print(matrix[0][i]) Correct Answer Incorrect Answer
    D print(matrix[i][i]) Correct Answer Incorrect Answer
    E print(matrix[N - 1 - i][i]) Correct Answer Incorrect Answer

    Solution

    The correct answer is D

    Practice Next
    ask-question