Вы находитесь на странице: 1из 6

/*PROGRAM TO READ A MATRIX , TRANSPOSE IT AND PRINT BOTH

THE MATRIX */
#include<stdio.h>
#include<conio.h>
main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n,
clrscr();
printf("Enter the size of A metrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of A metrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
/* transpose logic */
for(i=0;i<m;i++)
for(j=0;j<n;j++)
b[j][i]= a[i][j];
clrscr();
printf("\nA matrix is :\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%4d", a[i][j]);
printf("\n");
}
printf("\nTranspose of A matrix is :\n\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%4d", b[i][j]);
printf("\n");
}
getch();
}

/* PROGRAM TO READ TWO MATRICES MULTIPLY THEM AND PRINT


ALL THE
THREE MATRICES */
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,m,n,o,p;
printf("Enter the size of A metrix\n");
scanf("%d%d",&m,&n);
printf("Enter the size of B metrix\n");
scanf("%d%d",&o,&p);
if (n==o)
{
printf("Enter the elements of A metrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("Enter the elements of B metrix\n");
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<p;j++)
{
c[i][j] =0;
for (k=0;k<n;k++)
c[i][j] = c[i][j]+a[i][k]*b[k][j];
}
clrscr();
printf("\nA matrix is :\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%4d", a[i][j]);
printf("\n");
}
printf("\nB matrix is :\n\n");

for(i=0;i<o;i++)
{
for(j=0;j<p;j++)
printf("%4d", b[i][j]);
printf("\n");
}
printf("\nC matrix is :\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
printf("%4d", c[i][j]);
printf("\n");
}
}
else
printf("Multiplication not possible \n Please Reenter Correct Size\n");
getch();
}

/* PROGRAM TO READ TWO MATRICES Sub THEM AND PRINT ALL


THE THREE MATRICES */
#include<stdio.h>
#include<conio.h>
main()
{
int a[10][10],b[10][10],c[10][10],i,j,m,n;
printf("Enter the size of A and B metrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of A metrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("Enter the elements of B metrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
/* Subtract Logic */
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j] = a[i][j]-b[i][j];
clrscr();
printf("\nA matrix is :\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%4d", a[i][j]);
printf("\n");
}
printf("\nB matrix is :\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%4d", b[i][j]);
printf("\n");
}
printf("\nC matrix is :\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%4d", c[i][j]);

printf("\n");
}
getch();
}

//a 33 is more complicated and requires several helper equations


// to accomplish due to the term.
//These steps should help you calculate eigen values for a matrix
// that has ***3 REAL eigen values***.
Define x,y,z
//Use the equation from above to get your cubic equation and
// combine all constant terms possible to give you a reduced
// equation we will use a, b, c and d to denote the coefficients
// of this equation.
//Eqn = a + b + c + d = 0
x = ((3c/a) (b/a))/3
y = ((2b/a) (9bc/a) + (27d/a))/27
z = y/4 + x/27
Define I, j, k, m, n, p (so equations are not so cluttered)
i = sqrt(y/4 - z)
j = i^(1/3)
k = arccos(-(y/2i))
m = cos(k/3)
n = sqrt(3)*sin(k/3)
p = -b/3a
Define Eig1, Eig2, Eig3
Eig1 = 2j * m + p
Eig2 = -j * (m + n) + p

Вам также может понравиться