ช่วยสอนการย่อโปรแกรม C++ โดยใช้ loop หน่อยครับ

ตอนนี้ผมได้โจทย์มาให้เขียนโปรแกรม คูณเมทริกซ์ขนาด 3*3 สองเมทริกซ์
แล้วทีนี้ผมเขียนโปรแกรมด้วยโค้ดพื้นฐานมาก ๆ (ความรู้ผมมีเท่านี้จริง ๆ)
มันยาวมากครับ เกือบ 90 บรรทัด เลยอยากให้ช่วยสอนการใช้ loop ให้หน่อยครับ
ผมไม่เข้าใจหลักการทำงานของมันเลยสักนิด

อันนี้เป็นโปรแกรมของผมครับ

#include <stdio.h>
#include <conio.h>
main()
      {
                  int m1[3][3];
                  int m2[3][3];
                  int a,b,c,d,e,f,g,h,i;
                  printf("please enter your first matrix\n");
                  printf("matrix 1 11 : ",m1[0][0]);
                  scanf("%d",&m1[0][0]);
                  printf("matrix 1 12 : ",m1[0][1]);
                  scanf("%d",&m1[0][1]);
                  printf("matrix 1 13 : ",m1[0][2]);
                  scanf("%d",&m1[0][2]);
                  printf("matrix 1 21 : ",m1[1][0]);
                  scanf("%d",&m1[1][0]);
                  printf("matrix 1 22 : ",m1[1][1]);
                  scanf("%d",&m1[1][1]);
                  printf("matrix 1 23 : ",m1[1][2]);
                  scanf("%d",&m1[1][2]);
                  printf("matrix 1 31 : ",m1[2][0]);
                  scanf("%d",&m1[2][0]);
                  printf("matrix 1 32 : ",m1[2][1]);
                  scanf("%d",&m1[2][1]);
                  printf("matrix 1 33 : ",m1[2][2]);
                  scanf("%d",&m1[2][2]);
                                     printf("this is your first matrix\n");
                                     printf("%d\t",m1[0][0]);
                                     printf("%d\t",m1[0][1]);
                                     printf("%d\n",m1[0][2]);
                                     printf("%d\t",m1[1][0]);
                                     printf("%d\t",m1[1][1]);
                                     printf("%d\n",m1[1][2]);
                                     printf("%d\t",m1[2][0]);
                                     printf("%d\t",m1[2][1]);
                                     printf("%d\n",m1[2][2]);
                  printf("please enter your second matrix\n");
                  printf("matrix 2 11 : ",m2[0][0]);
                  scanf("%d",&m2[0][0]);
                  printf("matrix 2 12 : ",m2[0][1]);
                  scanf("%d",&m2[0][1]);
                  printf("matrix 2 13 : ",m2[0][2]);
                  scanf("%d",&m2[0][2]);
                  printf("matrix 2 21 : ",m2[1][0]);
                  scanf("%d",&m2[1][0]);
                  printf("matrix 2 22 : ",m2[1][1]);
                  scanf("%d",&m2[1][1]);
                  printf("matrix 2 23 : ",m2[1][2]);
                  scanf("%d",&m2[1][2]);
                  printf("matrix 2 31 : ",m2[2][0]);
                  scanf("%d",&m2[2][0]);
                  printf("matrix 2 32 : ",m2[2][1]);
                  scanf("%d",&m2[2][1]);
                  printf("matrix 2 33 : ",m2[2][2]);
                  scanf("%d",&m2[2][2]);
                                     printf("this is your second matrix\n");
                                     printf("%d\t",m2[0][0]);
                                     printf("%d\t",m2[0][1]);
                                     printf("%d\n",m2[0][2]);
                                     printf("%d\t",m2[1][0]);
                                     printf("%d\t",m2[1][1]);
                                     printf("%d\n",m2[1][2]);
                                     printf("%d\t",m2[2][0]);
                                     printf("%d\t",m2[2][1]);
                                     printf("%d\n",m2[2][2]);
                                                             a = (m1[0][0]*m2[0][0])+(m1[0][1]*m2[1][0])+(m1[0][2]*m2[2][0]);
                                                             b = (m1[0][0]*m2[0][1])+(m1[0][1]*m2[1][1])+(m1[0][2]*m2[2][1]);
                                                             c = (m1[0][0]*m2[0][2])+(m1[0][1]*m2[1][2])+(m1[0][2]*m2[2][2]);
                                                             d = (m1[1][0]*m2[0][0])+(m1[1][1]*m2[1][0])+(m1[1][2]*m2[2][0]);
                                                             e = (m1[1][0]*m2[0][1])+(m1[1][1]*m2[1][1])+(m1[1][2]*m2[2][1]);
                                                             f = (m1[1][0]*m2[0][2])+(m1[1][1]*m2[1][2])+(m1[1][2]*m2[2][2]);
                                                             g = (m1[2][0]*m2[0][0])+(m1[2][1]*m2[1][0])+(m1[2][2]*m2[2][0]);
                                                             h = (m1[2][0]*m2[0][1])+(m1[2][1]*m2[1][1])+(m1[2][2]*m2[2][1]);
                                                             i = (m1[2][0]*m2[0][2])+(m1[2][1]*m2[1][2])+(m1[2][2]*m2[2][2]);
                  printf("this matrix result\n");
                                     printf("%d\t",a);
                                     printf("%d\t",b);
                                     printf("%d\n",c);
                                     printf("%d\t",d);
                                     printf("%d\t",e);
                                     printf("%d\n",f);
                                     printf("%d\t",g);
                                     printf("%d\t",h);
                                     printf("%d\n",i);
                                     getch();
                                     }


อาจจะยาวไปหน่อย แต่ผมต้องการความช่วยเหลือจริง ๆ ครับ
ขอบคุณมาก ๆ ครับ
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่