Sunday, 3 September 2017

Matrix Programs - P7 Null Matrix in C Language


Introduction

A zero matrix is an mxn matrix consisting of all 0s (MacDuffee 1943, p. 27), denoted 0. Zero matrices are sometimes also known as null matrices (Akivis and Goldberg 1972, p. 71).
null-matrix.png
Image Courtesy: wikimedia.org
#include <stdio.h>
#define COLS 15
#define ROWS 15

int main(){
   int columns=COLS+1,rows=COLS+1;
   int a[COLS][ROWS];
   int i,j;
   printf("\nNULL MATRIX PROGRAM");
   printf("\n===================");
   /*Take the number of columns from user as input*/
   while(columns>COLS){
       printf("\nEnter number of columns: ");
       scanf("%d", &columns);
   }
   /*Take the number of rows from user as input*/
   while(rows>ROWS){
       printf("\nEnter number of rows: ");
       scanf("%d", &rows);
    }
   /*Assign value 0 to all rows and columns in matrix and print them.*/
   for(i=0;i<rows;i++){
       for(j=0;j<columns;j++){
           a[i][j]=0;
           printf("\na[%d][%d]: %d", i,j, a[i][j]);
       }
   }
   printf("\nThe value for a[%d][%d] is: \n\n",columns,rows);
   /*Print the Matrix in proper format*/
   for(i=0;i<rows;i++){
       printf("\t| ");
       for(j=0;j<columns;j++){
           printf(" %d ", a[i][j]);
       }
       printf(" |\n");
   }
   return 0;
}


NULL MATRIX PROGRAM
===================
Enter number of columns: 3

Enter number of rows: 4

a[0][0]: 0
a[0][1]: 0
a[0][2]: 0
a[1][0]: 0
a[1][1]: 0
a[1][2]: 0
a[2][0]: 0
a[2][1]: 0
a[2][2]: 0
a[3][0]: 0
a[3][1]: 0
a[3][2]: 0
The value for a[3][4] is:

       |  0  0  0  |
       |  0  0  0  |
       |  0  0  0  |
       |  0  0  0  |

Process returned 0 (0x0)   execution time : 3.241 s
Press any key to continue.

References:

  1. Weisstein, Eric W. "Zero Matrix." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/ZeroMatrix.html
  2. Akivis, M. A. and Goldberg, V. V. An Introduction to Linear Algebra and Tensors. New York: Dover, 1972.
  3. MacDuffee, C. C. Vectors and Matrices. Washington, DC: Math. Assoc. Amer., 1943

Cite this as:

  • Bhagchandani, Niraj. “Matrix Programs - P7 Null Matrix in C Language.” Everything Data Structure in C Language, Blogger, 4 Sept. 2017, edatastructure.blogspot.in/2017/09/matrix-programs-null-matrix-in-c.html.

About This article: 

  1. Google Drive: Download Matrix Program - Null Matrix In  C Language

  2. Blog Post: Blog Link- Matrix Program - Null Matrix In  C Language

No comments:

Post a Comment