-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecialMatrices.cpp
72 lines (65 loc) · 1.46 KB
/
SpecialMatrices.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//*******Diagonal Matrix********
/*
#include<iostream>
using namespace std;
int main(){
int a[] = {6,4,5,2};
int i,j;
for(i=0; i<4;i++){
for(j=0;j<4;j++){
if(i==j){
cout<<a[i]<<" ";
}
else{
cout<<"0"<<" ";
}
}
cout<<"\n";
}
}
*/
//*******TriDiagonal Matrix- Only main diagonal and the diagonal above, below it have elements, rest have 0
#include<iostream>
using namespace std;
int main(){
int a[] = {2,1,3,1,3,5,2,7,9,0}; // if you want the user to enter then keep the size of array as #Define MAX 4 3*MAX-2
int i,j;
int k=0;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(i-j==1||i-j==0||i-j==-1){
cout<<a[k]<<" ";
k++;
}
else{
cout<<"0"<<" ";
}
}
cout<<"\n";
}
return 0;
}
//************TRIANGULAR MATRIX**********
/*
#include<iostream>
using namespace std;
int main(){
int a[] = {2,5,1,0,3,1,4,2,7,0}; // if you want the user to enter then keep the size of array as #Define MAX 4
int i,j;
int k=0;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(i>=j){
cout<<a[k]<<" ";
k++;
}
else{
cout<<"0"<<" ";
}
}
cout<<"\n";
}
return 0;
}
*/
//**********Symmetric Matrix**************