Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SolutionClass{
- public void matrix(int n)
- {
- int[,] matrix = new int[n, n];
- int i,j;
- for(i=0; i<n; i++) { //assign values to the matrix
- for(j=0; j<n; j++) {
- if(i==j) {
- matrix[i,j]=0; //if row=column=> fill the matrix with 0
- }
- else if(i>j) {
- matrix[i,j]=-1;//if row>columns=> fill matrix with -1
- } else {
- matrix[i,j]=1; //if row<columns=> fill matrix with 1
- }
-
- }
- }
-
- for(i=0; i<n; i++) { //print the array
- for(j=0; j<n; j++) {
- Console.Write(matrix[i,j] + " ");
- }
- Console.WriteLine();
- }
-
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement