[C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
Moderator: mindphp, ผู้ดูแลกระดาน
-
- PHP Newbie
- โพสต์: 6
- ลงทะเบียนเมื่อ: 24/07/2011 3:26 pm
[C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
คือต้องการรับค่า m x n เท่าไหร่ก็ได้ แล้วมาแสดงผลให้เป็นตารางตามจำนวน m x n เลยอะครับ
คือผมไม่รู้จะเขียนออกมายังไงดี ให้มันแสดงผลในรูปของเมตริกซ์เลย เขียนออกมาทีไร แสดงผลเป็น แนวระนาบหมดเลย T ^ T
รบกวนผู้เชี่ยวชาญเขียนมาให้ผมดูเป็นแนวทางหน่อยนะครับ มะต้องหมดก็ได้ ขอทั้ง บวก ลบ และ คูณเลย
ขอบพระคุณมากครับ พอดีผมต้องใช้ไปเป็นโครงการก่อนสอบมิดเทอมอ่า ช่วยทีนะครับ
คือผมไม่รู้จะเขียนออกมายังไงดี ให้มันแสดงผลในรูปของเมตริกซ์เลย เขียนออกมาทีไร แสดงผลเป็น แนวระนาบหมดเลย T ^ T
รบกวนผู้เชี่ยวชาญเขียนมาให้ผมดูเป็นแนวทางหน่อยนะครับ มะต้องหมดก็ได้ ขอทั้ง บวก ลบ และ คูณเลย
ขอบพระคุณมากครับ พอดีผมต้องใช้ไปเป็นโครงการก่อนสอบมิดเทอมอ่า ช่วยทีนะครับ
-
- PHP Newbie
- โพสต์: 6
- ลงทะเบียนเมื่อ: 24/07/2011 3:26 pm
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
สงสัยจะไม่มีใครช่วยผมเลยแหะ TT ^ TT
ยังไงกะขอบคุณที่เข้ามาดูรายละเอียดกันนะครับ เดี๋ยวผมลองไปมั่วๆ เองละกัน
ขอบคุณมากครับ TT ^ TT
ยังไงกะขอบคุณที่เข้ามาดูรายละเอียดกันนะครับ เดี๋ยวผมลองไปมั่วๆ เองละกัน
ขอบคุณมากครับ TT ^ TT
-
- PHP Super Member
- โพสต์: 480
- ลงทะเบียนเมื่อ: 25/01/2010 11:57 pm
- ติดต่อ:
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
ฝึกเองเถอะครับมันเป็นประโยชน์มาก ตอนผมเรียนอาจารย์ออกข้อสอบให้เขียนลงในกระดาษเลย โจทย์เป็น [A]t * อีกตั้งหาก ไม่มีคอมไพล์เลอร์ไว้ตรวจสอบด้วย ลองเขียนเถอะครับจะได้เป็น อีกอย่างคงไม่มีใครเสียเวลามานั่งพิมพ์ให้หรอกครับ ยังไงทำมาก่อนติดตรงไหนก็เอามาโพสถามนะครับ
-
- PHP Newbie
- โพสต์: 6
- ลงทะเบียนเมื่อ: 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
- โพสต์: 6
- ลงทะเบียนเมื่อ: 24/07/2011 3:26 pm
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
oramaru เขียน:#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
- โพสต์: 480
- ลงทะเบียนเมื่อ: 25/01/2010 11:57 pm
- ติดต่อ:
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
อ่าดีแล้วครับทำเอง อิอิ
ถ้าทำเป็นแบบเลือกช้อย คราวหน้าแนะนำว่าให้ใช้ switch ดีกว่าครับ จะดูเป็นระเบียบกว่าครับ
ส่วนตัวแปรตัวไหนที่ใช้เก็บค่าแล้วก็แสดงผลแล้ว แล้วไม่ได้เอาไปใช้กับข้อมูลเดิมแล้ว แนะนำว่าให้เอาไปใช้กับข้อมูลอื่นต่อก็ได้ครับ แต่ต้องเป็นข้อมูลแบบเดียวกันนะครับ จะได้ไม่ต้องประกาศตัวแปรหลายตัว มันเปลืองพื้นที่นะครับ แล้วทำให้โค้ดดูเยอะขึ้นด้วย มันรกครับ
ถ้าทำเป็นแบบเลือกช้อย คราวหน้าแนะนำว่าให้ใช้ switch ดีกว่าครับ จะดูเป็นระเบียบกว่าครับ
ส่วนตัวแปรตัวไหนที่ใช้เก็บค่าแล้วก็แสดงผลแล้ว แล้วไม่ได้เอาไปใช้กับข้อมูลเดิมแล้ว แนะนำว่าให้เอาไปใช้กับข้อมูลอื่นต่อก็ได้ครับ แต่ต้องเป็นข้อมูลแบบเดียวกันนะครับ จะได้ไม่ต้องประกาศตัวแปรหลายตัว มันเปลืองพื้นที่นะครับ แล้วทำให้โค้ดดูเยอะขึ้นด้วย มันรกครับ
-
- PHP Newbie
- โพสต์: 6
- ลงทะเบียนเมื่อ: 24/07/2011 3:26 pm
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
ขอสอบถามเพิ่มเติมหน่อยครับ
ถ้าผมจะเอาคำสั่ง Continue to back menu อ่ะครับ ต้องเขียนยังไง ผมไม่เข้าใจ
ถ้าผมจะเอาคำสั่ง Continue to back menu อ่ะครับ ต้องเขียนยังไง ผมไม่เข้าใจ
-
- PHP Super Member
- โพสต์: 480
- ลงทะเบียนเมื่อ: 25/01/2010 11:57 pm
- ติดต่อ:
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/
-
- PHP Newbie
- โพสต์: 6
- ลงทะเบียนเมื่อ: 24/07/2011 3:26 pm
Re: [C] ช่วยด้วยครับ ผมไม่เข้าใจว่าจะต้องเขียนยังไงดี( โปรแกรมบวก ลบ และ คูณ เมตริกซ
ไม่เข้าใจครับtouleg เขียน:ใช้ 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/
คือต้องการให้มันเริ่มโปรแกรมใหม่อ่ะครับ เช่น Back to Menu (Y/N)
แล้วถ้าเลือก Y ก็คือโปรแกรมจะย้อนกลับไปเริ่มต้นใหม่ แต่ถ้าเลือก N ก็คือปิดโปรแกรมเลยอะครับ
-
- Similar Topics
- ตอบกลับ
- แสดง
- โพสต์ล่าสุด
-
-
โพสต์ใหม่ ขายคอนโดมิเนียม A.D ต.บางเสร่ อ.สัตหีบ จ.ชลบุรี ห้องสตูดิโอ 25.5 ตร.เมตร
โดย Tanadet » 11/09/2014 10:09 am » ใน พูดคุยเรื่องทั่วไป จับฉ่าย - 0 ตอบกลับ
- 667 แสดง
-
โพสต์ล่าสุด โดย Tanadet
11/09/2014 10:09 am
-
-
-
โพสต์ใหม่ บริษัท NEC ญี่ปุ่น โชว์รถยนต์บินได้ ทดสอบบิน สูงกว่า 3 เมตร!!!
โดย chatee supasand » 09/08/2019 2:15 pm » ใน MindPHP News & Feedback - 0 ตอบกลับ
- 407 แสดง
-
โพสต์ล่าสุด โดย chatee supasand
09/08/2019 2:15 pm
-
-
-
โพสต์ใหม่ บริษัท NEC ญี่ปุ่น โชว์รถยนต์บินได้ ทดสอบบิน สูงกว่า 3 เมตร!!!
โดย chatee supasand » 09/08/2019 12:27 pm » ใน IOT - Internet of things - 2 ตอบกลับ
- 623 แสดง
-
โพสต์ล่าสุด โดย chatee supasand
09/08/2019 2:13 pm
-
ผู้ใช้งานขณะนี้
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 77