-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzformofmatrix.cpp
More file actions
54 lines (45 loc) · 808 Bytes
/
zformofmatrix.cpp
File metadata and controls
54 lines (45 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//print z form of a matrix
#include<iostream>
using namespace std;
int main(){
int r, c, i, j;
cout<<"z form of a matrix\n";
cout<<"enter number of rows and columns (both must be the same number): ";
cin>>r>>c;
int m[r][c];
if(r!=c){
cout<<"z form of this matrix cannot be obtained\n";
}
else{
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<"enter element: ";
cin>>m[i][j];
}
cout<<endl;
}
cout<<"the matrix is:\n";
for(i=0; i<r; i++){
for(j=0; j<c; j++){
cout<<m[i][j]<<"\t";
}
cout<<endl;
}
cout<<"z form of the matrix is:\n";
for(j=0; j<c; j++){
i=0;
cout<<m[i][j]<<" ";
}
i=1; j=c-2;
while(i<r && j>0){
cout<<m[i][j]<<" ";
i++;
j--;
}
for(j=0; j<c; j++){
i=r-1;
cout<<m[i][j]<<" ";
}
}
return 0;
}