الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

اريد تصحيح هذا الكود ان امكن وبسرعة

بدأه السهم الثاقب في 3 أبريل 2009 · 2 رد · 361 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

اريد تصحيح هذا الكود ان امكن وبسرعة عاجلة

وهذا نص السوال

Write a program that reads 3 positive integers M,N and K. The program does the following:

1. Create two dynamic matrices of integers A=MxN and B=NxK .

2. Read the values of the two matrices A,B from the keyboard.

3. Multiply A, B and store the result in a dynamic matrix D, then display the result on screen.

4. Delete all allocated memory.

#include <iostream.h>
void main(){
int M,N,K;
int **A;
int **B;
int **D;
int sum=0;
   cout<<"inputinteger rows and culm:";
   cin>>M>>N>>K;
cout<<"INPUT THE FIRST MATRIX ";
A= new int *[M];
for (int i=0;i<M;i++)
{
*(A+i)=new int[N];
for(int j=0;j<N;j++)
cin>>*(*(A+i)+j);
}
cout<<"input the second matrix ";
B=new int*[N];
for(i=0;i<N;i++)
{
*(B+i)=new int[K];
for(int j=0;j<K;j++)
cin>>*(*(B+i)+j);
}
D=new int *[M];
for(i=0;i<M;i++)
*(D+1)=new int[K];
for(i=0;i<M;i++)
for(int h=0;h<K;h++)
{
sum=0;
for(int e=0;e<N;e++)
sum+=*(*(A+i)+e)**(*(B+e)+h);
*(*(D+i)+h)=sum;
}
cout<<"the multiply is :"<<endl<<endl;
for(i=0;i<M;i++)
for (int j=0;j<K;j++)
cout<<*(*(D+i)+i)<<"";
cout<<endl;


for (i=0;i<M;i++)
delete[]*(A+i);
delete[]A;
A='\0';
for(i=0;i<N;i++)
delete[]*(B+i);
delete[]B;
B='\0';
for(i=0;i<M;i++)
delete[]*(D+i);
delete[]D;
D='\0';
}
#2

السلام عليكــم ورحمـة الله وبركاتــه ،،

تفضل أخى الكريم


void main()
{
int M,N,K;
int **A;
int **B;
int **D;
int sum=0,i,j,h;
cout<<"inputinteger rows and culm:";
cin>>M>>N>>K;
A= new int *[M];
for ( i=0;i<M;i++)
{
A=new int[N];
}
B=new int*[N];
for(i=0;i<N;i++)
{
B=new int[K];
}
cout<<"INPUT THE FIRST MATRIX ";
for (i=0;i<M;i++)
{
for (j=0;j<N;j++)
cin>>A[j];
}
cout<<"input the second matrix ";
for (i=0;i<N;i++)
{
for (j=0;j<K;j++)
cin>>B[j];
}
D=new int *[M];
for(i=0;i<M;i++)
D=new int[K];
for(i=0;i<M;i++)
for(h=0;h<K;h++)
{
sum=0;
for(int e=0;e<N;e++)
sum+=*(*(A+i)+e)**(*(B+e)+h);
*(*(D+i)+h)=sum;
}
cout<<"the multiply is :"<<endl<<endl;
for(i=0;i<M;i++)
{
for (int j=0;j<K;j++)
cout<<*(*(D+i)+i)<<" ";
cout<<endl;
}
cout<<endl;
for (i=0;i<M;i++)
delete[]*(A+i);
delete[]A;
A=0;
for(i=0;i<N;i++)
delete[]*(B+i);
delete[]B;
B=0;
for(i=0;i<M;i++)
delete[]*(D+i);
delete[]D;
D=0;
}
#include <iostream.h>

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#3

:ty:

مواضيع مشابهة