Professional Documents
Culture Documents
AIM:
Demonstrate the use of two-
dimensional arrays to solve a given
problem.
Program 1
PROBLEM Write a program to perform matrix multiplication. Dimensions of matrices
STATEMENT : will be decided by user.
PROGRAM: ALGORITHM:
int main()
{
int A[3][3],B[3][3],C[3][3],i,j,k,sum;
printf("Enter the element of Matrix A:");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
scanf("%d",&A[i][j]);
}
printf("Enter the element of Matrix B:");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
scanf("%d",&B[i][j]);
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
sum=0;
for(k=0;k<=2;k++)
{
sum=sum+A[i][k]*B[k][j];
C[i][j]=sum;
}
}
}
for(i=0;i<=2;i++)
{ printf("\n");
for(j=0;j<=2;j++)
printf(" %d ",C[i][j]);
}
return 0;
}
.
PROGRAM: ALGORITHM:
Step 1: START
Step 5: Using for loop take input from user of employee ID and
employee age and store it in data[n][3].
Step 6: Using for loop and if else statement find the retirement year of
employee.
Step 8:STOP.
Code:
#include <stdio.h>
int main()
int n,c;
scanf("%d", &c);
scanf("%d", &n);
int data[n][3];
scanf("%d", &data[i][0]);
scanf("%d", &data[i][1]);
else
{
data[i][2] = c;
printf("EmployeeID\tEmployeeAge\tRetirementYear\n");
printf("%d\t\t", data[i][j]);
printf("\n");
return 0;
}
RESULT: Arranged the data.
INPUT:
OUTPUT:
Program 3
Write a program to calculate the determinant of matrix. Dimensions of
PROBLEM
matrix will be decided by user.
STATEMENT :
PROGRAM:
ALGORITHM:
.Step 1:START
Step 3: Take element of matrix A as input from user and store it int
A[3][3].
Step 4: Do d1=A[0][0]*A[1][1]*A[2][2];
d2=A[0][1]*A[1][2]*A[2][0];
d3=A[2][1]*A[1][0]*A[0][2];
d4=A[2][0]*A[1][1]*A[0][2];
d5=A[2][1]*A[1][2]*A[0][0];
d6=A[0][1]*A[1][0]*A[2][2];
d=d1+d2+d3-d4-d5-d6;
Step 5: Print d
Step 6:Stop
Code:
#include <stdio.h>
int main()
{
int A[3][3],d1,d2,d3,d4,d5,d6,d;
printf("Enter the element of Matrix A:");
for(int i=0;i<=2;i++)
{
for(int j=0;j<=2;j++)
scanf("%d",&A[i][j]);
}
d1=A[0][0]*A[1][1]*A[2][2];
d2=A[0][1]*A[1][2]*A[2][0];
d3=A[2][1]*A[1][0]*A[0][2];
d4=A[2][0]*A[1][1]*A[0][2];
d5=A[2][1]*A[1][2]*A[0][0];
d6=A[0][1]*A[1][0]*A[2][2];
d=d1+d2+d3-d4-d5-d6;
INPUT: A=3,2,1,7,5,9,1,0,2
OUTPUT: