Skip to main content

Posts

Showing posts from October, 2017

Simple 2D Array

// Matrix #include<stdio.h> #define SIZE 5 int main() {     int a[SIZE][SIZE],j,i,row,column;     printf("Enter the Rows : ");     scanf("%d",&row);     printf("Enter the Columns : ");     scanf("%d",&column);     printf("Enter Elements of Array \n");     for(i=0;i<row;i++)     {         for(j=0;j<column;j++)         {             printf("a[%d][%d] : ",i,j);             scanf("%d",&a[i][j]);         }     }     printf("\n\n");     for(i=0;i<row;i++)     {         printf("|");         for(j=0;j<column;j++)         {             printf("%3d",a[i][j]);         }       ...

Static Matrix Multiplication

// Matrix Multiplication #include<stdio.h> int main() {     int a[3][3],b[3][3],c[3][3],d[3][3];     int i,j,k;         printf("Enter Elements of Matrix - A\n");         for(i=0;i<3;i++)         {             for(j=0;j<3;j++)             {                 printf("a[%d][%d] : ",i,j);                 scanf("%d",&a[i][j]);             }         }         printf("Enter Elements of Matrix - B \n");         for(i=0;i<3;i++)         {             for(j=0;j<3;j++)             {                 printf("b[%d][%d] : ",i,j);  ...

Transpose of Matrix

// Transpose of Matrix #include<stdio.h> #define SIZE 5 int main() {     int a[SIZE][SIZE],transpose[SIZE][SIZE];     int i,j,r,c;     printf("Enter Rows of Matrix : ");     scanf("%d",&r);     printf("Enter Rows of Matrix : ");     scanf("%d",&c);         for(i=0;i<r;i++)     {         for(j=0;j<c;j++)         {             printf("Enter Elements [%d][%d] : ",i,j);             scanf("%d",&a[i][j]);         }     }     for(i=0;i<r;i++)     {         for(j=0;j<c;j++)         {             transpose[j][i] = a[i][j];         }     }     printf("Matrix \n");     for(i=0;i...

Dynamic Matrix Multiplication

// Matrix Multiplication #include<stdio.h> #define SIZE 5 int main() {     int a[SIZE][SIZE],b[SIZE][SIZE],c[SIZE][SIZE],d[SIZE][SIZE];     int i,j,k,r1,r2,c1,c2;     printf("Enter the Rows of Matrix - A : ");     scanf("%d",&r1);     printf("Enter the Columns of Matrix - A : ");     scanf("%d",&c1);     printf("Enter the Rows of Matrix - B : ");     scanf("%d",&r2);     printf("Enter the Columns of Matrix - B : ");     scanf("%d",&c2);     if(c1 == r2)     {         printf("Enter Elements of Matrix - A\n");         for(i=0;i<r1;i++)         {             for(j=0;j<c1;j++)             {                 printf("a[%d][%d] : ",i,j);       ...

Matrix Subtraction

// Matrix Subtraction #include<stdio.h> #define SIZE 5 int main() {     int a[SIZE][SIZE],b[SIZE][SIZE];     int i,j,r1,r2,c1,c2;     printf("Enter the Rows of Matrix - A : ");     scanf("%d",&r1);     printf("Enter the Columns of Matrix - A : ");     scanf("%d",&c1);     printf("Enter the Rows of Matrix - B : ");     scanf("%d",&r2);     printf("Enter the Columns of Matrix - B : ");     scanf("%d",&c2);     if(c1 == r2)     {         printf("Enter Elements of Matrix - A\n");         for(i=0;i<r1;i++)         {             for(j=0;j<c1;j++)             {                 printf("a[%d][%d] : ",i,j);                 scan...

Matrix Addition

// Matrix Addition #include<stdio.h> #define SIZE 5 int main() {     int a[SIZE][SIZE],b[SIZE][SIZE];     int i,j,r1,r2,c1,c2;     printf("Enter the Rows of Matrix - A : ");     scanf("%d",&r1);     printf("Enter the Columns of Matrix - A : ");     scanf("%d",&c1);     printf("Enter the Rows of Matrix - B : ");     scanf("%d",&r2);     printf("Enter the Columns of Matrix - B : ");     scanf("%d",&c2);     if(c1 == r2)     {         printf("\nEnter Elements of Matrix - A\n");         for(i=0;i<r1;i++)         {             for(j=0;j<c1;j++)             {                 printf("a[%d][%d] : ",i,j);                 scanf...

Upper Triangular Matrix

// Upper Triangular Matrix #include<stdio.h> int main() {     int i,j,k,m,s=1,rc;             printf("Enter Row and Columns : ");     scanf("%d",&rc);         for(i=1;i<rc;i++)     {         for(m=1;m<=i;m++)         {             printf("  0");         }         for(j=rc-1;j>i;j--)         {             printf("%3d",s);             s++;         }         printf("\n");     }     return 0; }

Lower Triangular Matrix

// Lower Triangular Matrix #include<stdio.h> int main() {     int i,j,k,m,s=1,rc;     printf("Enter the No of Raws and Columns : ");     scanf("%d",&rc);       for(i=1;i<rc;i++)     {         for(m=0;m<i;m++) // for loop which prints numbers.         {             printf("%3d",s);             s++;         }         for(j=rc;j>i;j--) // for loop which prints 0.         {             printf("  0");         }         printf("\n");     }     return 0; }

Address Matrix (In shape)

// Address Matrix in shape #include<stdio.h> int main() {     int i,j,rc;     printf("Enter the Number of Rows and Columns : ");     scanf("%d",&rc);     for(i=0;i<rc;i++)     {         for(j=i;j<rc;j++)         {             printf("%3d%d",i,j);         }         printf("\n");     }     return 0; }

Address Matrix (In shape)

// Address Array printing in shape #include<stdio.h> int main() {     int i,j,rc;     printf("Enter the Number of Rows and Columns : ");     scanf("%d",&rc);     for(i=0;i<rc;i++)     {         for(j=0;j<=i;j++)         {             printf("%2d%d",i,j);         }         printf("\n");     }     return 0; }

Address Matrix (Simple)

// Matrix which Prints Address of Array (simple) #include<stdio.h> int main() {     int i,j,rc;     printf("Enter the Number of Rows and Columns : ");     scanf("%d",&rc);     printf("\n");     for(i=0;i<rc;i++)     {     printf("|");         for(j=0;j<rc;j++)         {             printf("%3d%d",i,j);         }         printf(" | \n");     }     return 0; }

Simple Matrix

// Simple Matrix Upto n Numbers. (Dynamic) #include<stdio.h> int main() {     int i,j,k=1,rc;     printf("Enter the No of Columns : ");     scanf("%d",&rc);     for(i=0;i<rc;i++)     {          printf("|");         for(j=0;j<rc;j++,k++)         {             printf("%3d",k);         }         printf(" | \n");     }     return 0; }

Identity Matrix

// Identity Matrix #include<stdio.h> #define SIZE 10 int main() {     int a[SIZE][SIZE];     int rc,i,j;     printf("THIS IS SQUARE MATRIX SO ROWS AND COLUMNS WILL BE SAME");     printf("\n\nEnter the No. of Rows and Columns : ");     scanf("%d",&rc);     for(i=0;i<rc;i++)     {         for(j=0;j<rc;j++)         {             if(i == j)             {                 a[i][j] = 1;             }             else             {                 a[i][j] = 0;             }         }         printf("\n");     }     for(i=0;i<...

Null Matrix

//Null Matrix #include<stdio.h> #define SIZE 10 int main() {     int i,j,rc;     printf("THIS IS SQUARE MATRIX SO ROWS AND COLUMNS MUST BE SAME\n\n");     printf("Enter the Number of Rows and Columns : ");     scanf("%d",&rc);     for(i=0;i<rc;i++)     {         printf("|");         for(j=0;j<rc;j++) // for loop that prints zero.         {             printf(" 0 ");         }         printf(" |\n");     }     return 0; }