جواد_سرابادانی
یک شنبه 12 خرداد 1387, 23: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]);
}
#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]);
}