Tuesday, 14 January 2014

Program of two dimension ARRAY in c

    /* program to Add Matrix*/
#include<stdio.h>
main()
{
int x[3][4],y[3][4],z[3][4],c,d;
for(c=0;c<3;++c)
{
for(d=0; d<4; ++d)
{
printf("enter the element in matrix x");
scanf("%d",&x[c][d]);
}
}
for(c=0; c<3; ++c)
{
for(d=0;d<4;++d)
{
printf("enter the element in matrix y");
scanf("%d",&y[c][d]);
}
}
for(c=0; c<3; ++c)
{
for(d=0; d<4; ++d)
{
z[c][d]=x[c][d]+y[c][d];
}
}
printf("entment of z is :-\n");
for(c=0; c<3; ++c);
{
for(d=0; d<3; ++d)
{
printf("%d\t",z[c][d]);
}
printf("\n");
}



    /* program to multiply two matrix */
#include<stdio.h>
main()
{
int x[3][3],y[3][3],r[3][3]={0},i,j,k;
for(i=0; i<3; ++i)
{
for(j=0; j<3; ++j)
{
printf("enter the element in matrix x");
scanf("%d",&x[i][j]);
}
}
for(i=0; i<3; ++i)
{
for(j=0; j<3; ++j)
{
printf("enter the element in matrix y");
scanf("%d",&y[i][j]);
}
}
for(i=0; i<3; ++i)
{
for(j=0; j<3; ++j)
{
for(k=0; k<3; ++k)
{
   r[i][j]=r][i][j]+x[i][k]*y[k][j];
}
}
}
printf("product are :-\n");
for(i=0;i<3; ++i)
{
for(j=0; j<3; ++j)
{
printf("%d \t",r[i][j]);
}
printf("\n");
}
}




    /* program of transpose matrix */
#include<stdio.h>
main()
{
int x[3][3], r[3][3], i,j;
for(i=0; i<3; ++i)
{
for(j=0; j<3; ++j)
{
printf("enter the element of matrix x");
scanf("%d",&x[i][j]);
}
}
for(i=0; i<3; ++i)
{
for(j=0  j<3; ++j)
{
r[i][j]=x[j][i];
}
}
printf("tranpose is:-\n");
for(i=0; i<3; ++i)
{
for(j=0; j<3; ++j)
{
printf("%d \t ", r[i][j]);
}
printf("\n");
}
}

No comments:

Post a Comment