C programming

Saturday, January 17, 2009

#include #include void main() { clrscr(); int mat1[10][10],sub[10][10],sum[10][10],mat2[10][10],i,j,n; printf("Enter the size of the matrix:"); scanf("%d",&n); printf("Enter the element of the(%d*%d) first matrix: \n\n",n,n); //Input first matrix. for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { printf("Element[%d][%d]",i,j); scanf("%d",&mat1[i][j]); } printf("\n"); } printf("Enter the element of the (%d*%d) second matrix:\n\n",n,n); // Input second matrix. for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { printf("Element[%d][%d]",i,j); scanf("%d",&mat2[i][j]); } printf("\n"); } //print matrix 1. printf(" MATRIX 1 \n"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { printf("%3d ",mat1[i][j]); } printf("\n"); } printf("\n\n"); //print matrix 2. printf(" MATRIX 2 \n"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { printf("%3d ",mat2[i][j]); } printf("\n"); } printf("The summation of the matrix:\n"); //Determination of the summation of two matrix && print. for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { sum[i][j]=mat1[i][j]+mat2[i][j]; printf("%3d ",sum[i][j]); } printf("\n"); } printf("The subtraction of the matrix:\n"); //Determination of the subtraction of two matrix && print. for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { sub[i][j]=mat1[i][j]-mat2[i][j]; printf("%3d ",sub[i][j]); } printf("\n"); } getch(); }

0 comments:

Visitors

PlugIn.ws - Free Hit Counter, Web Site Statistics, Traffic Analysis

  © Blogger template Leaving by Ourblogtemplates.com 2008

Back to TOP