Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Sum of Main Diagonal | Advanced Array Topics
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C++ Arrays

bookChallenge: Sum of Main Diagonal

Tâche

Swipe to start coding

Write a function that calculates the sum of the main diagonal of a 2D integer array. The main diagonal consists of elements where the row index and column index are equal.

Requirements:

  • Declare and initialize a 2D array in main.
  • Pass the array and its size to a function.
  • Use nested loops or direct indexing to access diagonal elements.
  • Return the diagonal sum from the function.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 3
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

bookChallenge: Sum of Main Diagonal

Glissez pour afficher le menu

Tâche

Swipe to start coding

Write a function that calculates the sum of the main diagonal of a 2D integer array. The main diagonal consists of elements where the row index and column index are equal.

Requirements:

  • Declare and initialize a 2D array in main.
  • Pass the array and its size to a function.
  • Use nested loops or direct indexing to access diagonal elements.
  • Return the diagonal sum from the function.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 3
single

single

some-alt