PROGRAM 1:
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n;
printf("enter the no. of rows and columns\n");
scanf("%d%d",&m,&n);
printf("enter the elements of first matrix \n");
for(i=0;i<m;i++)
{
{
for(j=0;j<n;j++)
scanf("%d",*(a+i)+j);
}
}
printf("enter the elements of second matrix \n");
for(i=0;i<m;i++){
{
for(j=0;j<n;j++)
scanf("%d",*(b+i)+j);
}
}
printf("sum of the given matrices is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
*(*(c+i)+j)=*(*(a+i)+j)+*(*(b+i)+j);
printf("%d\t",*(*(c+i)+j));
}
printf("\n");
}
}
OUTPUT:
OUTPUT:
PROGRAM 3:
PROGRAM TO TRANSPOSE A GIVEN MATRIX
PROGRAM TO FIND
ADDITION OF TWO MATRIX
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n;
printf("enter the no. of rows and columns\n");
scanf("%d%d",&m,&n);
printf("enter the elements of first matrix \n");
for(i=0;i<m;i++)
{
{
for(j=0;j<n;j++)
scanf("%d",*(a+i)+j);
}
}
printf("enter the elements of second matrix \n");
for(i=0;i<m;i++){
{
for(j=0;j<n;j++)
scanf("%d",*(b+i)+j);
}
}
printf("sum of the given matrices is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
*(*(c+i)+j)=*(*(a+i)+j)+*(*(b+i)+j);
printf("%d\t",*(*(c+i)+j));
}
printf("\n");
}
}
OUTPUT:
PROGRAM 2:
PROGRAM FOR SUBTRACTION OF TWO
MATRICES
#include<stdio.h>
void main()
{int
a[10][10],b[10][10],c[10][10],i,j,m,n;
printf("enter the no. of
rows and columns\n");
scanf("%d%d",&m,&n);
printf("enter the elements
of first matrix \n");
for(i=0;i<m;i++)
{
{for(j=0;j<n;j++)
scanf("%d",*(a+i)+j);
}
}
printf("enter the elements
of second matrix \n");
for(i=0;i<m;i++)
{
{for(j=0;j<n;j++)
scanf("%d",*(b+i)+j);
}
}
printf("sum of the given
matrices is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
*(*(c+i)+j)=*(*(a+i)+j)-*(*(b+i)+j);
printf("%d\t",*(*(c+i)+j));
}
printf("\n");
}
}
OUTPUT:
PROGRAM 3:
PROGRAM TO TRANSPOSE A GIVEN MATRIX
#include<stdio.h>
void read(int x[10][10],int m,int n);
void disp(int x[10][10],int m,int n);
int main()
{int a[10][10],b[10][10],m,n;
printf("enter the order of matrix\n");
scanf("%d %d",&m,&n);
printf("enter the elements of matrix a\n");
read(a,m,n);
printf("the transpose of matrix is:\n");
disp(a,m,n);
}
void read(int x[10][10],int m,int n)
{int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&x[i][j]);
}
}
}
void disp(int x[10][10],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++){
printf("%d\t",x[j][i]);
}
printf("\n");
}
}
OUTPUT:
PROGRAM 4:
void read(int x[10][10],int m,int n);
void disp(int x[10][10],int m,int n);
int main()
{int a[10][10],b[10][10],m,n;
printf("enter the order of matrix\n");
scanf("%d %d",&m,&n);
printf("enter the elements of matrix a\n");
read(a,m,n);
printf("the transpose of matrix is:\n");
disp(a,m,n);
}
void read(int x[10][10],int m,int n)
{int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&x[i][j]);
}
}
}
void disp(int x[10][10],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++){
printf("%d\t",x[j][i]);
}
printf("\n");
}
}
OUTPUT:
PROGRAM 4:
PROGRAM TO IMPLEMENT
MULTIPLICATION OF MATRIX
#include<stdio.h>
#include<stdlib.h>
main()
{
int
a[5][5],b[5][5],c[5][5],m,n,p,q,i,j,k;
printf("enter order of
matrix a\n");
scanf("%2d%2d",&m,&n);
printf("enter order of
matrix b \n");
scanf("%2d%2d",&p,&q);
if(n!=p){
printf("multiplication not
possible \n");
exit(0);
}
printf("enter elments of mat
a\n");
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",*(a+i)+j);
}
}
printf("enter elments of mat
b \n");
for(i=0;i<p;i++){
for(j=0;j<q;j++){
scanf("%d",*(b+i)+j);
}
}
for(i=0;i<m;i++){
for(j=0;j<q;j++){
*(*(c+i)+j)=0;
for(k=0;k<p;k++){
*(*(c+i)+j)=*(*(c+i)+j)+*(*(a+i)+k)**(*(b+k)+j);
}
}
}
printf("multiplication is as
follows:\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++){
printf("%3d",*(*(c+i)+j));
}
printf("\n");
}
}
OUTPUT:
No comments:
Post a Comment
we are hear to discuss your queries ,so please feel free to ask any of your queries.