-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmenuDrivenDiagonal.cpp
More file actions
87 lines (84 loc) · 1.74 KB
/
menuDrivenDiagonal.cpp
File metadata and controls
87 lines (84 loc) · 1.74 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
using namespace std;
void create(int a[], int n)
{
for (int i = 1; i <= n; i++)
{
cout << "Enter the value of [" << i << "][" << i << "] ";
cin >> a[i];
}
cout << endl;
}
void setdata(int a[], int i, int j, int k)
{
if (i == j)
{
a[i] = k;
}
cout << endl;
}
int getdata(int a[], int i, int j)
{
if (i = j)
return a[i];
else
return 0;
}
void display(int a[], int n)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i == j)
cout << a[i] << " ";
else
cout << "0 ";
}
cout << endl;
}
cout << endl;
}
int main()
{
int *a, n, ch, x, i, j;
cout << "Enter the dimension of matrix" << endl;
cin >> n;
a = new int[n];
do
{
cout << endl;
cout << "Choice 1: Create" << endl;
cout << "Choice 2: Get" << endl;
cout << "Choice 3: Set" << endl;
cout << "Choice 4: Display" << endl;
cin >> ch;
switch (ch)
{
case 1:
create(a, n);
// cout<<endl;
break;
case 2:
cout << "Enter indices" << endl;
cin >> i >> j;
cout << getdata(a, i, j) << endl;
// cout</<endl;
break;
case 3:
cout << "Enter indices" << endl;
cin >> i >> j;
cout << "Enter the value " << endl;
cin >> x;
setdata(a, i, j, x);
// cout<<endl;
break;
case 4:
display(a, n);
// cout<<endl;
break;
default:
break;
}
} while (ch > 0 && ch < 5);
}