Professional Documents
Culture Documents
Fundamentals of Programming: Lab Report # 11
Fundamentals of Programming: Lab Report # 11
Fundamentals of
Programming
(LAB)
Lab Report # 11
Submitted To:
Student Name:
Reg. Number:
BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 3
Task (01):
Write a c++ program to multiply a 3 by 3 matrix.
Source Code:
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int a[3][3], b[3][3], mult[3][3], i, j, k;
6.
7. cout << endl << "Enter elements of matrix 1:" << endl;
8. for(i = 0; i < 3; ++i)
9. for(j = 0; j < 3; ++j)
10. {
11. cout << "Enter element a" << i + 1 << j + 1 << " : ";
12. cin >> a[i][j];
13. }
14. cout << endl << "Enter elements of matrix 2:" << endl;
15. for(i = 0; i < 3; ++i)
16. for(j = 0; j < 3; ++j)
17. {
18. cout << "Enter element b" << i + 1 << j + 1 << " : ";
19. cin >> b[i][j];
20. }
21. for(i = 0; i < 3; ++i)
22. for(j = 0; j < 3; ++j)
23. {
24. mult[i][j]=0;
25. }
26. for(i = 0; i < 3; ++i)
27. for(j = 0; j < 3; ++j)
28. for(k = 0; k < 3; ++k)
29. {
30. mult[i][j] += a[i][k] * b[k][j];
31. }
32. cout << endl << "Output Matrix: " << endl;
33. for(i = 0; i < 3; ++i)
34. for(j = 0; j < 3; ++j)
35. {
36. cout << " " << mult[i][j];
37. if(j == 3-1)
38. cout << endl;
39. }
40.
41. return 0;
42. }
BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 3
Screenshot of Output:
BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB