void menu(){
clrscr();
char ch;
cout<<“Select your task.\n”;
cout<<“a. write.\n”;
cout<<“b. add.\n”;
cout<<“c. multi.\n”;
cout<<“d. sub.\n”;
cout<<“e. transpose.\n”;
cout<<“f. replace.\n”;
ch = getch();
switch(ch){
case ‘a’:
writemat();
break;
case ‘b’:
addmat();
break;
case ‘c’:
multmat();
break;
case ‘d’:
submat();
break;
case ‘e’:
trans();
break;
case ‘f’:
replace();
break;
}
}
void main(){
cout<<“Enter matrix size.”;
cin>>k;
readmat();
menu();
}
void readmat(){
clrscr();
cout<<“Enter matrix 1.”;
for(int i=0; i<k; i++)
for(int j=0; j<k; j++){
cout<<“\nmat1[“<<(i+1)<<“]”<<“[“<<(j+1)<<“]”;
cin>>mat1[i][j];
}
}
void writemat(){
clrscr();
for(int i=0; i<k; i++){
for(int j=0; j<k; j++){
cout<<“\t”<<mat1[i][j];
}
cout<<“\n”;
}
getch();
menu();
}
void addmat(){
clrscr();
cout<<“Enter matrix 2.”;
for(int i=0; i<k; i++)
for(int j=0; j<k; j++){
cout<<“\nmat2[“<<(i+1)<<“]”<<“[“<<(j+1)<<“]”;
cin>>mat2[i][j];
//gotoxy(15, 2);
clreol();
}
for(i=0; i<k; i++){
for(int j=0; j<k; j++)
mat3[i][j] = mat1[i][j] + mat2[i][j];
}
for(i=0; i<k; i++){
for(int j=0; j<k; j++){
cout<<“\t”<<mat3[i][j];
}
cout<<“\n”;
}
getch();
menu();
}
void multmat(){
clrscr();
cout<<“Enter matrix 2.”;
for(int i=0; i<k; i++)
for(int j=0; j<k; j++){
cout<<“\nmat2[“<<(i+1)<<“]”<<“[“<<(j+1)<<“]”;
cin>>mat2[i][j];
//gotoxy(15, 2);
clreol();
}
for(i=0; i<k; i++){
for(int j=0; j<k; j++)
mat3[i][j] = mat1[i][j] * mat2[i][j];
}
for(i=0; i<k; i++){
for(int j=0; j<k; j++){
cout<<“\t”<<mat3[i][j];
}
cout<<“\n”;
}
getch();
menu();
}
void submat(){
clrscr();
cout<<“Enter matrix 2.”;
for(int i=0; i<k; i++)
cout<<“\nmat2[“<<(i+1)<<“]”<<“[“<<(j+1)<<“]”;
cin>>mat2[i][j];
//gotoxy(15, 2);
clreol();
}
for(i=0; i<k; i++){
for(int j=0; j<k; j++)
mat3[i][j] = mat1[i][j] – mat2[i][j];
}
for(i=0; i<k; i++){
for(int j=0; j<k; j++){
cout<<“\t”<<mat3[i][j];
}
cout<<“\n”;
}
getch();
menu();
}
void trans(){
clrscr();
for(int i=0; i<k; i++)
for(int j=0; j<k; j++)
for(i=0; i<k; i++){
for(int j=0; j<k; j++)
cout<<“\t”<<mat3[i][j];
cout<<“\n”;
}
getch();
menu();
}
void replace(){
clrscr();
unsigned int m[1][90];
int i, j;
cout<<“Enter i & j:”;
cin>>i>>j;
clreol();
for(int l=0; l<k; l++)
for(int n=0; n<k; n++)
mat3[l][n] = mat1[l][n];
for(l=0; l<k; l++){
m[l] = mat1[i][l];
mat3[j][l] = m[1][l];
}
for(i=0; i<k; i++){
for(int j=0; j<k; j++){
cout<<“\t”<<mat3[i][j];
}
cout<<“\n”;
}
getch();
menu();
}
|
دیدگاهتان را بنویسید