PDA

View Full Version : لطفا بگید اشکال در کجای برنامه است



جواد_سرابادانی
یک شنبه 12 خرداد 1387, 22:50 عصر
برنامه ای که با استفاده از تابع trasposeترانهاده ی روی یک ماتریس را حساب کند.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
///////////////moarefi tavabe///////////
void read2arr(int,int,float[][5]);
void transpose(int,int,float[][5]);
void print2arr(int,int,float[][5]);
void main()
{
float A[5][5],A_T[5][5];
int M/*rows*/,N/*columns*/;
cout<<"how many rows?:";
cin>>M;
cout<<"how many columns?:";
cin>>N;
read2arr(M,N,A);
/*A_T=A;*/
for(int i=0;i<M;i++)
for(int j=0;j<N;j++)
A_T[i][j]=A[i][j];
transpose(M,N,A_T);
print2arr(M,N,A_T);
}
void read2arr(int M,int N,float b[][5])
{
for(int i=0;i<M;i++)
{
for(int j=0;j<N;j++)
cout<<"Enter b["<<i<<"]["<<j<<"]j";
cin>>b[i][j];
}
}
void transpose(int M,int N,float b[][5])
{
float temp;
for(int i=0;i<M;i++)
for(int j=i+1;j<N;j++)
{
temp=b[i][j];
b[i][j]=b[j][i];
b[j][i]=temp;
}
}
void print2arr(int M,int N,float b[][5])
{
for(int i=0;i<M;i++)
for(int j=0;j<N;j++)
printf("%d",b[j][i]);
}

MRHagh
دوشنبه 13 خرداد 1387, 07:11 صبح
لطفا بگید اشکال در کجای برنامه است
تقریبا همه جاش ... !!!
برای محاسبه ترانهاده یک ماتریس M*N تنها به یک ماتریس N*M و دو حلقه بصورت تودرتو نیاز دارید که در هربار گردش , درایه [i][j] ماتریس دوم را برابر دارایه [j][i] ماتریس اول قرار دهد . به این ترتیب جای سطر و ستون ها را در دو ماتریس با هم عوض کردید .
موفق باشید ...

MOHSEN8000
دوشنبه 13 خرداد 1387, 09:35 صبح
برنامه ای که با استفاده از تابع trasposeترانهاده ی روی یک ماتریس را حساب کند.


البته همون جوری که آقای MRHagh گفتن اصلا نیازی نیست به این کارا. خب اگه به جای این که بخوای ترانهاده ی ماتریس b رو بریزی داخل خودش از یه ماتریس دیگه استفاده کنی خیلی
راحت تره. من برنامه رو یکم درست کردم و کامپایل شد. ولی اجراش نکردم ببینم درسته یا نه.


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
///////////////moarefi tavabe///////////
void read2arr(int,int,float[][5]);
void transpose(int,int,float[][5]);
void print2arr(int,int,float[][5]);
void main()
{
float A[5][5],A_T[5][5];
int M/*rows*/,N/*columns*/;
cout<<"how many rows?:";
cin>>M;
cout<<"how many columns?:";
cin>>N;
read2arr(M,N,A);
/*A_T=A;*/
for(int i=0;i<M;i++)
for(int j=0;j<N;j++){
A_T[i][j]=A[i][j];
}
transpose(M,N,A_T);
print2arr(M,N,A_T);
}

void read2arr(int M,int N,float b[][5]){
for(int i=0;i<M;i++){
for(int j=0;j<N;j++){
cout<<"Enter b["<<i<<"]["<<j<<"]j";
cin>>b[i][j];
}
}

}
void transpose(int M,int N,float b[][5]){
float temp;
for(int i=0;i<M;i++)
for(int j=i+1;j<N;j++){
temp=b[i][j];
b[i][j]=b[j][i];
b[j][i]=temp;
}
}

void print2arr(int M,int N,float b[][5])
{
for(int i=0;i<M;i++){
for(int j=0;j<N;j++){
printf("%f",b[j][i]);
}
printf("\n");
}

}