-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntitled1.cpp
More file actions
163 lines (161 loc) · 2.17 KB
/
Untitled1.cpp
File metadata and controls
163 lines (161 loc) · 2.17 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int ans;
int power;
int matrix[2][2];
struct node *link;
}*start;
int i,j,m[2][2],power1,m2[2][2]={NULL,NULL,NULL,NULL},y[2][2]={NULL,NULL,NULL,NULL},b=0;
void insert()
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("\nenter your value [%d][%d]: ",i,j);
scanf("%d",&m[i][j]);
}
}
printf("\nenter your power: ");
scanf("%d",&power1);
struct node *p;
p=(struct node *)malloc(sizeof(struct node));
p->power=power1;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
p->matrix[i][j]=m[i][j];
}
}
p->link=start;
start=p;
}
void display()
{
struct node *temp;
temp=start;
printf("\n");
while(temp->link!=NULL)
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d ",temp->matrix[i][j]);
}
printf("\n");
}
temp=temp->link;
printf("\n\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d ",temp->matrix[i][j]);
}
printf("\n");
}
printf("\n");
}
void pow()
{
int y1;
struct node *temp;
temp=start;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
y[i][j]=0;
m2[i][j]=0;
}
}
while(temp!=NULL)
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
y[i][j]=temp->matrix[i][j];
}
}
for(y1=0;y1<temp->power;y1++)
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
y[i][j]=(y[i][j])*(temp->matrix[i][j]);
}
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
m2[i][j]+=y[i][j];
}
}
temp=temp->link;
}
}
void display_ans()
{
printf("\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d ",m2[i][j]);
}
printf("\n");
}
printf("\n");
}
void delete1()
{
struct node *temp;
temp=start;
temp=temp->link;
start->link=NULL;
delete start;
start=temp;
}
main()
{
do
{
printf("\n1.insert\n2.display\n3.calculation\n4.display ans\n5.exit\n6.delete\n\n");
printf("enter your choice: ");
switch(getche())
{
case '1':
insert();
break;
case '2':
display();
break;
case '3':
pow();
break;
case '4':
display_ans();
break;
case '5':
return 0;
break;
case '6':
delete1();
break;
default:
printf("choice invalid........\n\n");
break;
}
}while(1);
getch();
}