Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Find the sum of diagonal elements of a 3*3 integer matrix. How to write this program?
Find the sum of diagonal elements of a 3*3 integer matrix. How to write this program?
Hello. We have this problem in class today. The code is as follows, without compilation and testing. # include & ltstdio,h & gtint main(){ int a[3][3]; //You can define the initial value as (int I = 0;; I<3; i++)for(int j = 0; j & lt3; j++){ a[I][j]= j; //assignment, I did it casually} intsum = 0; //Define variables to store diagonal sums (int b = 0;; b & gt3; b++){ sum = = sum+a[b][b]; } } }