0% found this document useful (0 votes)
20 views8 pages

Sams Sir Lab - 02

The document contains multiple C programs for performing various matrix operations including addition, subtraction, multiplication, and transposition, as well as calculating standard deviation, variance, and mean. Each program includes input and output examples, along with the author's name, roll number, and section. The programs are designed to demonstrate fundamental concepts in matrix manipulation and statistical calculations.

Uploaded by

Arnab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views8 pages

Sams Sir Lab - 02

The document contains multiple C programs for performing various matrix operations including addition, subtraction, multiplication, and transposition, as well as calculating standard deviation, variance, and mean. Each program includes input and output examples, along with the author's name, roll number, and section. The programs are designed to demonstrate fundamental concepts in matrix manipulation and statistical calculations.

Uploaded by

Arnab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

PROGRAM-01: Develop a C Program for Addition of Two Matrices.

Input OUTPUT
include<stdio.h> Matrix A:
main() 5 4
{ 4 4
int a[2][2]={5,4,4,4};
int b[2][2]={6,7,4,8}; Matrix B:
int c[2][2]; 6 7
int i,j; 4 8
printf("\nMatrix A:\n");
for(i=0;i<2;i++) Matrix C:
{ 11 11
for(j=0;j<2;j++) 8 12
{
printf("%d\t",a[i][j]);
} Name:Pujon Samadder
printf("\n"); Roll:2101014
} Section:A
printf("\nMatrix B:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\nMatrix C:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
printf("\n\nName:Pujon Samadder\nRoll:2101014\nSection:A");
getch();
}
PROGRAM-02: Develop a C Program for Subtraction of Two Matrices.
INTPUT OUTPUT
#include<stdio.h>
main() Matrix A:
{ 5 4
int a[2][2]={5,4,4,4}; 4 4
int b[2][2]={6,7,4,8};
int c[2][2]; Matrix B:
int i,j; 6 7
printf("\nMatrix A:\n"); 4 8
for(i=0;i<2;i++)
{ Matrix C:
for(j=0;j<2;j++) -1 -3
{ 0 -4
printf("%d\t",a[i][j]);
}
printf("\n"); Name:Pujon Samadder
} Roll:2101014
printf("\nMatrix B:\n"); Section:A
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]-b[i][j];
}
}
printf("\nMatrix C:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
printf("\n\nName:Pujon Samadder\nRoll:2101014\nSection:A");
getch();
}
PROGRAM-03: Develop a C Program for Multiplication of Two Matrices.
INPUT OUTPUT

#include<stdio.h> Output
main()
{ Matrix A:
int a[2][2]={5,4,4,4}; 5 4
int b[2][2]={6,7,4,8}; 4 4
int c[2][2];
int i,j,k; Matrix B:
printf("\nMatrix A:\n"); 6 7
for(i=0;i<2;i++) 4 8
{
for(j=0;j<2;j++) Matrix C:
{ 46 67
printf("%d\t",a[i][j]); 40 60
}
printf("\n");
} Name:Pujon Samadder
printf("\nMatrix B:\n"); Roll:2101014
for(i=0;i<2;i++) Section:A
{
for(j=0;j<2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j];
for(k=0;k<2;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\nMatrix C:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
printf("\n\nName:Pujon Samadder\nRoll:2101014\
nSection:A");
getch();
}

PROGRAM-04: Develop a C Program for Multiplication of Two Matrices.


INPUT OUTPUT
#include<stdio.h>
main() Enter the elements of A
{ 1
int a[2][3]; 2
int b[3][4]; 34
int c[2][4]; 5
int i,j,k; 6
printf("\nEnter the elements of A\n"); 6
for(i=0;i<2;i++) 7
{
for(j=0;j<3;j++) Enter the elements of B
{ 82
scanf("%d\t",&a[i][j]); 3
} 4
} 5
printf("\nEnter the elements of B\n"); 6
for(i=0;i<3;i++) 7
{ 7
for(j=0;j<4;j++) 6
{ 5
scanf("%d\t",&b[i][j]); 6
} 7
} 8
printf("\nMatrix A:\n");
for(i=0;i<2;i++) Matrix A:
{ 1 2 34
for(j=0;j<3;j++) 5 6 6
{
printf("%d\t",a[i][j]); Matrix B:
} 7 82 3 4
printf("\n"); 5 6 7 7
} 6 5 6 7
printf("\nMatrix B:\n");
for(i=0;i<3;i++) Matrix C:
{ 221 264 221 256
for(j=0;j<4;j++) 101 476 93 104
{
printf("%d\t",b[i][j]);
} Name:Pujon Samadder
printf("\n"); Roll:2101014
} Section:A
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\nMatrix C:\n");
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
printf("\n\nName:Pujon Samadder\nRoll:2101014\
nSection:A");
getch();
}

PROGRAM-05: Develop a C Program for Transpose of a Matrix.


INPUT OUTPUT

#include<stdio.h> Matrix A:
main() 2 3 5
{ 7 9 3
int a[2][3]={2,3,5,7,9,3};
int b[3][2];
int i,j; The Transpose Matrix B:
printf("Matrix A:\n"); 2 7
for(i=0;i<2;i++) 3 9
{ 5 3
for(j=0;j<3;j++)
{ Name:Pujon Samadder
printf("%d\t",a[i][j]); Roll:2101014
} Section:A
printf("\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
b[j][i]=a[i][j];
}
printf("\n");
}
printf("The Transpose Matrix B:\n");
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("\nName:Pujon Samadder\nRoll:2101014\
nSection:A");
getch();
}
PROGRAM-06: Develop a C Program for Determination of Standard
Deviation, Variance and Mean.
INPUT OUTPUT

#include<stdio.h> Enter no. of elements:11


main() Enter all elements:
{ 2
float a[1000], m, v, s; 5
float s1=0, s2=0; 3
8
int i,n;
5
printf("Enter no. of elements:"); 6
scanf("%d",&n); 7
printf("Enter all elements:\n"); 4
3
for(i=0; i<n; i++) 8
{ 9
scanf("%f",&a[i]);
} Standard Deviation= 2.23
for(i=0; i<n; i++) Variance=4.98
{ Mean=5.45
s1=s1+a[i];
Name: Pujon Samadder
}
Roll:2101014
m= s1/n; Section:A
for(i=0; i<n;i++)
{
s2= s2+pow((a[i]-m),2);
}
v= s2/n;
s= pow(v,0.5);

printf("\nStandard Deviation= %0.2f",s);


printf("\nVariance=%0.2f",v);
printf("\nMean=%0.2f",m);

printf("\n\nName: Pujon Samadder\nRoll:2101014\


nSection:A");
getch();
}

You might also like