[C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
Moderators: mindphp, ผู้ดูแลกระดาน
-
- PHP Newbie
- Posts: 6
- Joined: 24/07/2011 3:26 pm
[C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
คือต้องการรับค่า m x n เท่าไหร่ก็ได้ แล้วมาแสดงผลให้เป็นตารางตามจำนวน m x n เลยอะครับ
คือผมไม่รู้จะเขียนออกมายังไงดี ให้มันแสดงผลในรูปของเมตริกซ์เลย เขียนออกมาทีไร แสดงผลเป็น แนวระนาบหมดเลย T ^ T
รบกวนผู้เชี่ยวชาญเขียนมาให้ผมดูเป็นแนวทางหน่อยนะครับ มะต้องหมดก็ได้ ขอทั้ง บวก ลบ และ คูณเลย
ขอบพระคุณมากครับ พอดีผมต้องใช้ไปเป็นโครงการก่อนสอบมิดเทอมอ่า ช่วยทีนะครับ
คือผมไม่รู้จะเขียนออกมายังไงดี ให้มันแสดงผลในรูปของเมตริกซ์เลย เขียนออกมาทีไร แสดงผลเป็น แนวระนาบหมดเลย T ^ T
รบกวนผู้เชี่ยวชาญเขียนมาให้ผมดูเป็นแนวทางหน่อยนะครับ มะต้องหมดก็ได้ ขอทั้ง บวก ลบ และ คูณเลย
ขอบพระคุณมากครับ พอดีผมต้องใช้ไปเป็นโครงการก่อนสอบมิดเทอมอ่า ช่วยทีนะครับ
-
- PHP Newbie
- Posts: 6
- Joined: 24/07/2011 3:26 pm
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
สงสัยจะไม่มีใครช่วยผมเลยแหะ TT ^ TT
ยังไงกะขอบคุณที่เข้ามาดูรายละเอียดกันนะครับ เดี๋ยวผมลองไปมั่วๆ เองละกัน
ขอบคุณมากครับ TT ^ TT
ยังไงกะขอบคุณที่เข้ามาดูรายละเอียดกันนะครับ เดี๋ยวผมลองไปมั่วๆ เองละกัน
ขอบคุณมากครับ TT ^ TT
-
- PHP Super Member
- Posts: 480
- Joined: 25/01/2010 11:57 pm
- Contact:
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
ฝึกเองเถอะครับมันเป็นประโยชน์มาก ตอนผมเรียนอาจารย์ออกข้อสอบให้เขียนลงในกระดาษเลย โจทย์เป็น [A]t * อีกตั้งหาก ไม่มีคอมไพล์เลอร์ไว้ตรวจสอบด้วย ลองเขียนเถอะครับจะได้เป็น อีกอย่างคงไม่มีใครเสียเวลามานั่งพิมพ์ให้หรอกครับ ยังไงทำมาก่อนติดตรงไหนก็เอามาโพสถามนะครับ
-
- PHP Newbie
- Posts: 6
- Joined: 24/07/2011 3:26 pm
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
#include <stdio.h>
#include <conio.h>
void main()
{
int m1[10][10],i,j,c,k,m2[10][10],add[10][10],mult[10][10],r1,c1,r2,c2;
printf("Enter number of rows and columns of A matrix MAX 10\n");
scanf("%d%d",&r1,&c1);
printf("Enter number of rows and columns of B matrix MAX 10\n");
scanf("%d%d",&r2,&c2);
clrscr();
printf("1. Addition Matrix\n\n");
printf("2. Deletion Matrix\n\n");
printf("3. Multiply Matrix\n\n");
printf("Choose : ");
scanf("%d",&c);
clrscr();
/*################################# Addition ################################*/
if(c==1)
{
if(r1==r2&&c1==c2)
{
printf("Enter rows and columns of A matrix \n");
printf("Row wise numbers\n\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[j]);
}
printf("You have entered the A matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[j]);
printf("\n");
}
printf("Enter rows and columns of B matrix \n");
printf("Again row wise numbers\n\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[j]);
}
printf("You have entered the B matrix as follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[j]);
printf("\n");
}
printf("The result of the addition is as follows;\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
add[j]=m1[j]+m2[j];
printf("%d\t",add[j]);
}
printf("\n");
}
}
/*################################# Deletion ################################*/
else if(c==2)
{
if(r1==r2&&c1==c2)
{
printf("Enter rows and columns of A matrix \n");
printf("Row wise numbers\n\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[j]);
}
printf("You have entered the A matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[j]);
printf("\n");
}
printf("Enter rows and columns of B matrix \n");
printf("Again row wise numbers\n\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
printf("You have entered the B matrix as follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[i][j]);
printf("\n");
}
printf("The result of the deletion is as follows;\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
add[i][j]=m1[i][j]-m2[i][j];
printf("%d\t",add[i][j]);
}
printf("\n");
}
}
}
/*################################# Multiply ################################*/
else if(c==3)
{
if(c1==r2)
{
printf("The result of the multiplication is as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j]+=m1[i][k]*m2[k][j];
/*mult[0][0]=m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0]+m1[0][2]*m2[2][0];*/
}
printf("%d\t",mult[i][j]);
}
printf("\n");
}
}
}
getch();
}
/*else
{
printf("Matrix multiplication cannot be done");
}*/
}
***** ติดตรงที่ว่า ตอนผมรันโปรแกรม ผมเลือก choice ข้อที่ 2 - 3 แล้วมัน ไม่รันให้อ่ะครับ มึนๆ งงๆ
#include <conio.h>
void main()
{
int m1[10][10],i,j,c,k,m2[10][10],add[10][10],mult[10][10],r1,c1,r2,c2;
printf("Enter number of rows and columns of A matrix MAX 10\n");
scanf("%d%d",&r1,&c1);
printf("Enter number of rows and columns of B matrix MAX 10\n");
scanf("%d%d",&r2,&c2);
clrscr();
printf("1. Addition Matrix\n\n");
printf("2. Deletion Matrix\n\n");
printf("3. Multiply Matrix\n\n");
printf("Choose : ");
scanf("%d",&c);
clrscr();
/*################################# Addition ################################*/
if(c==1)
{
if(r1==r2&&c1==c2)
{
printf("Enter rows and columns of A matrix \n");
printf("Row wise numbers\n\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[j]);
}
printf("You have entered the A matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[j]);
printf("\n");
}
printf("Enter rows and columns of B matrix \n");
printf("Again row wise numbers\n\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[j]);
}
printf("You have entered the B matrix as follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[j]);
printf("\n");
}
printf("The result of the addition is as follows;\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
add[j]=m1[j]+m2[j];
printf("%d\t",add[j]);
}
printf("\n");
}
}
/*################################# Deletion ################################*/
else if(c==2)
{
if(r1==r2&&c1==c2)
{
printf("Enter rows and columns of A matrix \n");
printf("Row wise numbers\n\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[j]);
}
printf("You have entered the A matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[j]);
printf("\n");
}
printf("Enter rows and columns of B matrix \n");
printf("Again row wise numbers\n\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
printf("You have entered the B matrix as follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[i][j]);
printf("\n");
}
printf("The result of the deletion is as follows;\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
add[i][j]=m1[i][j]-m2[i][j];
printf("%d\t",add[i][j]);
}
printf("\n");
}
}
}
/*################################# Multiply ################################*/
else if(c==3)
{
if(c1==r2)
{
printf("The result of the multiplication is as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j]+=m1[i][k]*m2[k][j];
/*mult[0][0]=m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0]+m1[0][2]*m2[2][0];*/
}
printf("%d\t",mult[i][j]);
}
printf("\n");
}
}
}
getch();
}
/*else
{
printf("Matrix multiplication cannot be done");
}*/
}
***** ติดตรงที่ว่า ตอนผมรันโปรแกรม ผมเลือก choice ข้อที่ 2 - 3 แล้วมัน ไม่รันให้อ่ะครับ มึนๆ งงๆ
-
- PHP Newbie
- Posts: 6
- Joined: 24/07/2011 3:26 pm
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
oramaru wrote:#include <stdio.h>
#include <conio.h>
void main()
{
int m1[10][10],i,j,c,k,m2[10][10],add[10][10],mult[10][10],r1,c1,r2,c2;
printf("Enter number of rows and columns of A matrix MAX 10\n");
scanf("%d%d",&r1,&c1);
printf("Enter number of rows and columns of B matrix MAX 10\n");
scanf("%d%d",&r2,&c2);
clrscr();
printf("1. Addition Matrix\n\n");
printf("2. Deletion Matrix\n\n");
printf("3. Multiply Matrix\n\n");
printf("Choose : ");
scanf("%d",&c);
clrscr();
/*################################# Addition ################################*/
if(c==1)
{
if(r1==r2&&c1==c2)
{
printf("Enter rows and columns of A matrix \n");
printf("Row wise numbers\n\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[j]);
}
printf("You have entered the A matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[j]);
printf("\n");
}
printf("Enter rows and columns of B matrix \n");
printf("Again row wise numbers\n\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[j]);
}
printf("You have entered the B matrix as follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[j]);
printf("\n");
}
printf("The result of the addition is as follows;\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
add[j]=m1[j]+m2[j];
printf("%d\t",add[j]);
}
printf("\n");
}
}
/*################################# Deletion ################################*/
else if(c==2)
{
if(r1==r2&&c1==c2)
{
printf("Enter rows and columns of A matrix \n");
printf("Row wise numbers\n\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[j]);
}
printf("You have entered the A matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[j]);
printf("\n");
}
printf("Enter rows and columns of B matrix \n");
printf("Again row wise numbers\n\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
printf("You have entered the B matrix as follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[i][j]);
printf("\n");
}
printf("The result of the deletion is as follows;\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
add[i][j]=m1[i][j]-m2[i][j];
printf("%d\t",add[i][j]);
}
printf("\n");
}
}
}
/*################################# Multiply ################################*/
else if(c==3)
{
if(c1==r2)
{
printf("The result of the multiplication is as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j]+=m1[i][k]*m2[k][j];
/*mult[0][0]=m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0]+m1[0][2]*m2[2][0];*/
}
printf("%d\t",mult[i][j]);
}
printf("\n");
}
}
}
getch();
}
/*else
{
printf("Matrix multiplication cannot be done");
}*/
}
***** ติดตรงที่ว่า ตอนผมรันโปรแกรม ผมเลือก choice ข้อที่ 2 - 3 แล้วมัน ไม่รันให้อ่ะครับ มึนๆ งงๆ
ผมแก้ได้ละคับ ><
-
- PHP Super Member
- Posts: 480
- Joined: 25/01/2010 11:57 pm
- Contact:
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
อ่าดีแล้วครับทำเอง อิอิ
ถ้าทำเป็นแบบเลือกช้อย คราวหน้าแนะนำว่าให้ใช้ switch ดีกว่าครับ จะดูเป็นระเบียบกว่าครับ
ส่วนตัวแปรตัวไหนที่ใช้เก็บค่าแล้วก็แสดงผลแล้ว แล้วไม่ได้เอาไปใช้กับข้อมูลเดิมแล้ว แนะนำว่าให้เอาไปใช้กับข้อมูลอื่นต่อก็ได้ครับ แต่ต้องเป็นข้อมูลแบบเดียวกันนะครับ จะได้ไม่ต้องประกาศตัวแปรหลายตัว มันเปลืองพื้นที่นะครับ แล้วทำให้โค้ดดูเยอะขึ้นด้วย มันรกครับ
ถ้าทำเป็นแบบเลือกช้อย คราวหน้าแนะนำว่าให้ใช้ switch ดีกว่าครับ จะดูเป็นระเบียบกว่าครับ
ส่วนตัวแปรตัวไหนที่ใช้เก็บค่าแล้วก็แสดงผลแล้ว แล้วไม่ได้เอาไปใช้กับข้อมูลเดิมแล้ว แนะนำว่าให้เอาไปใช้กับข้อมูลอื่นต่อก็ได้ครับ แต่ต้องเป็นข้อมูลแบบเดียวกันนะครับ จะได้ไม่ต้องประกาศตัวแปรหลายตัว มันเปลืองพื้นที่นะครับ แล้วทำให้โค้ดดูเยอะขึ้นด้วย มันรกครับ
-
- PHP Newbie
- Posts: 6
- Joined: 24/07/2011 3:26 pm
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
ขอสอบถามเพิ่มเติมหน่อยครับ
ถ้าผมจะเอาคำสั่ง Continue to back menu อ่ะครับ ต้องเขียนยังไง ผมไม่เข้าใจ
ถ้าผมจะเอาคำสั่ง Continue to back menu อ่ะครับ ต้องเขียนยังไง ผมไม่เข้าใจ
-
- PHP Super Member
- Posts: 480
- Joined: 25/01/2010 11:57 pm
- Contact:
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
ใช้ while(1) ครอบตั้งแต่แสดงเมนูจนจบโปรแกรม โดยถ้าจะให้จบโปรแกรม ก็ตรวจสอบค่าที่รับจากการเลือกเมนู สมมุติว่ากด 'q' ออกจากโปรแกรม ก็ตรวจสอบหลังจากรับค่าเลือกเมนู ว่าถ้าเป็น 'q' ก็ให้ break; มันก็จะออกจากลูปทำให้จบโปรแกรมได้ ถ้าเลือกเมนูอื่น เมื่อทำงานจนจบแล้วมันก็จะวนกลับมาแสดงเมนูใหม่ แล้วก็รับค่าเลือกเมนูใหม่ไปอย่างนี้เรื่อยๆ จนกว่าจะกด q ออกจากโปรแกรม
ถ้าจะ clear หน้าจอด้วยแล้วค่อยแสดงเมนูใหม่ก็ให้ใช้ clrscr(); หลังจากทำงานเสร็จแล้ว (ก่อนวนกลับขึ้นมา)
clrscr() จะต้อง include<conio.h> ด้วย เฉพาะเขียนกับ turbo c++ หรือ Borland C++
ถ้าเป็นบน Visual Studio จะไม่มีคำสั่งนี้ใน conio.h แล้ว
ถ้าอยากได้ก็เอาโค้ดนี้ไปใช้ อาจารย์ผมเขียนไว้ ก็อบไปใส่ไฟล์แล้วเซพเป็น .h นะครับ
http://thanwa.cpe.mut.ac.th/howto/thaiconsole/
ถ้าจะ clear หน้าจอด้วยแล้วค่อยแสดงเมนูใหม่ก็ให้ใช้ clrscr(); หลังจากทำงานเสร็จแล้ว (ก่อนวนกลับขึ้นมา)
clrscr() จะต้อง include<conio.h> ด้วย เฉพาะเขียนกับ turbo c++ หรือ Borland C++
ถ้าเป็นบน Visual Studio จะไม่มีคำสั่งนี้ใน conio.h แล้ว
ถ้าอยากได้ก็เอาโค้ดนี้ไปใช้ อาจารย์ผมเขียนไว้ ก็อบไปใส่ไฟล์แล้วเซพเป็น .h นะครับ
http://thanwa.cpe.mut.ac.th/howto/thaiconsole/
-
- Similar Topics
- Replies
- Views
- Last post
-
-
ช่วยด้วยครับ โค้ดไม่ถูกสีักที
by death note » 05/02/2013 9:13 pm » in Programming - C/C++ & java & Python - 0 Replies
- 1301 Views
-
Last post by death note
05/02/2013 9:13 pm
-
-
-
ช่วยด้วยครับ ไม่รู้เซ็ตคุกกี้ผิดตรงไหน มันฟ้องตลอดเลย
by zamie » 01/02/2013 8:55 pm » in Programming - PHP - 5 Replies
- 2303 Views
-
Last post by Chayyim
05/02/2013 9:31 am
-
-
-
ช่วยด้วยครับ dreamweaver เมนูตารางด้านซ้ายชอบเลื่อนลงเมื่อใส่รูปหรือข้อความด้านขวา
by cmchamping » 19/08/2017 4:38 pm » in Programming - PHP - 0 Replies
- 390 Views
-
Last post by cmchamping
19/08/2017 4:38 pm
-
-
-
ช่วยด้วยครับ Magento2 ขึ้นแบบนี้
by Wongsadudee Markii » 20/02/2019 11:19 pm » in Magento user Guide Knowledge (เลิกทำเนื้อหา) - 3 Replies
- 1853 Views
-
Last post by mindphp
21/02/2019 4:45 am
-
-
-
ช่วยด้วยครับ.. ลบ Security Center ก็ไม่ได้
by holyslayersp » 23/05/2011 5:29 pm » in ถาม - ตอบ คอมพิวเตอร์ - 2 Replies
- 2207 Views
-
Last post by holyslayersp
24/05/2011 7:42 pm
-
-
-
เกี่ยวกับการ insert รูปครับ ช่วยด้วยครับ
by RonnaritBooyyarit » 20/06/2011 10:19 am » in Programming - PHP - 2 Replies
- 1077 Views
-
Last post by dexjanghan
22/06/2011 10:06 am
-
-
-
ช่วยด้วยครับ เปิดเวบแล้วพวกโมดูล ปักอิน ภาษาอันเออเร่ออะครับ
by kitsana_na » 11/07/2012 2:15 pm » in ปัญหาการใช้ phpBB3, SMF, Joomla, Wordpress, CMS, CRM - 7 Replies
- 2961 Views
-
Last post by mindphp
11/07/2012 5:07 pm
-
Who is online
Users browsing this forum: No registered users and 7 guests