Professional Documents
Culture Documents
Code For Matrix Multiplication
Code For Matrix Multiplication
Program 1
ALGORITHM: 1. Declare variables for storing values of rows and columns of matrices
int i,j;
}
printf("\n");
}
}
int main()
{
int r1, c1, r2, c2,k;
if(c1==r2)
{
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
res[i][j] = 0;
for(k=0;k<c1;k++)
{
res[i][j]+=a[i][k]*b[k][j];
}
}
}
printf("The Multiplication of the Two Matrices is:\n\n");
print_matrix(r1, c2, res);
}
else
printf("The matrices cannot be multiplied.");
}
RESULT:
OUTPUT:
5 1 3
5 3 4
6 0 3
Program 2
PROBLEM Write a program which reads the current year followed by N followed by a
STATEMENT: list of N employee numbers and their current ages. Produce a list showing
the years in which the employees retire (become 65 years old). If more than
one employee retires in a given year then include them all under the same
heading.
int main()
{
int emp[10][3];
int n,i,e,r;
int cy;
printf("\nEnter Current Year:");
scanf("%d",&cy);
printf("\nEnter Number of Employees:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEmployee no.:");
scanf("%d",&emp[i][0]);
printf("Current Age.:");
scanf("%d",&emp[i][1]);
emp[i][2]=cy+65-emp[i][1];
}
printf("\nThe order is of the form:\nRetriement Year, Employee
Number, Current Age of Employee\n");
sort_emp(emp,n);
print_emp(emp,n);
return 0;
}
RESULT:
Employee no.:1
Current Age.:29
Employee no.:2
Current Age.:33
Employee no.:3
Current Age.:57
Employee no.:4
Current Age.:45
Employee no.:5
Current Age.:63
OUTPUT:
2023 5 63
2029 3 57
2041 4 45
2053 2 33
2057 1 29