mardi 1 novembre 2016

(c ) how to print main diagonal of matrix and how to fill matrix with random numbers

so i have matrix a[i] [j] for example i = j = d(for example 3) . How can i fill it with random numbers and then i need to show main diagonal and another diagonal over and below matrix. Almost all examples that i found were for c++ but i need to do it in c.

I thought about cycle but don't know how to write it correctly . According to my idea it should take point a[0][0] and i = 0 ,i++ 1 , i < d and j=0 j++ 1 ,j < d. This will be main diagonal. And another one is i = d , i-- 1, j=0 , j++ 1. Therefore it will take both diagonals and then print it though printf . Hope for your support.

How it should look like

1 6 11 16 - main diagonal

13 10 7 4 - additional diagonal


1 2 3 4

5 6 7 8

9 10 11 12 - random matrix

13 14 15 16


1 6 11 16 - main diagonal

13 10 7 4 - additional diagonal




Aucun commentaire:

Enregistrer un commentaire