Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
otsall
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2f19a3a9
authored
Oct 01, 2018
by
otsall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
matrices
parent
327044a5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
Lab4/matrices.c
Lab4/matrices.c
0 → 100644
View file @
2f19a3a9
#include <stdio.h>
#include <stdlib.h>
int
main
(){
int
x
,
y
,
size
,
byhand
,
diagonal1
=
1
,
diagonal2
=
1
;
printf
(
"input the size of the matrices
\n
"
);
scanf
(
"%d"
,
&
x
);
y
=
x
;
size
=
x
;
int
matrix1
[
x
][
y
],
matrix2
[
x
][
y
],
resultingMatrix
[
x
][
y
];
printf
(
"type 1 to intput the elements of the matrices by hand. other inputs will generate random elements
\n
"
);
scanf
(
"%d"
,
&
byhand
);
if
(
byhand
!=
1
){
for
(
x
=
0
;
x
<
size
;
x
++
){
for
(
y
=
0
;
y
<
size
;
y
++
){
matrix1
[
x
][
y
]
=
rand
()
%
500
;
matrix2
[
x
][
y
]
=
rand
()
%
500
;
}
}
}
else
{
printf
(
"enter elements of first matrix
\n
"
);
for
(
x
=
0
;
x
<
size
;
x
++
){
for
(
y
=
0
;
y
<
size
;
y
++
){
scanf
(
"%d"
,
&
matrix1
[
x
][
y
]);
}
}
printf
(
"enter elements of the second matrix
\n
"
);
for
(
x
=
0
;
x
<
size
;
x
++
){
for
(
y
=
0
;
y
<
size
;
y
++
){
scanf
(
"%d"
,
&
matrix2
[
x
][
y
]);
}
}
}
printf
(
"first matrix:
\n
"
);
for
(
x
=
0
;
x
<
size
;
x
++
){
for
(
y
=
0
;
y
<
size
;
y
++
){
printf
(
"%d, "
,
matrix1
[
x
][
y
]);
}
printf
(
"
\n
"
);
}
printf
(
"second matrix:
\n
"
);
for
(
x
=
0
;
x
<
size
;
x
++
){
for
(
y
=
0
;
y
<
size
;
y
++
){
printf
(
"%d, "
,
matrix2
[
x
][
y
]);
}
printf
(
"
\n
"
);
}
printf
(
"sum of the matrices is as follows:
\n
"
);
for
(
x
=
0
;
x
<
size
;
x
++
){
for
(
y
=
0
;
y
<
size
;
y
++
){
resultingMatrix
[
x
][
y
]
=
matrix1
[
x
][
y
]
+
matrix2
[
x
][
y
];
printf
(
"%d, "
,
resultingMatrix
[
x
][
y
]);
}
printf
(
"
\n
"
);
}
printf
(
"substraction of the matrices is as follows:
\n
"
);
for
(
x
=
0
;
x
<
size
;
x
++
){
for
(
y
=
0
;
y
<
size
;
y
++
){
resultingMatrix
[
x
][
y
]
=
matrix1
[
x
][
y
]
-
matrix2
[
x
][
y
];
printf
(
"%d, "
,
resultingMatrix
[
x
][
y
]);
}
printf
(
"
\n
"
);
}
printf
(
"the sum of the multiplication of the diagonals of the first matrix:
\n
"
);
//using byhand because i dont want to declare another variable. it acts as the sum of the multiplication of the diagonals.
for
(
x
=
0
;
x
<
size
;
x
++
){
y
=
x
;
diagonal1
=
matrix1
[
x
][
y
]
*
diagonal1
;
}
for
(
x
=
0
;
x
<
size
;
x
++
){
y
=
size
-
1
-
x
;
diagonal2
=
matrix1
[
x
][
y
]
*
diagonal2
;
}
byhand
=
diagonal1
+
diagonal2
;
printf
(
"%d
\n
"
,
byhand
);
diagonal1
=
1
;
diagonal2
=
1
;
printf
(
"the sum of the multiplication of the diagonals of the second matrix:
\n
"
);
for
(
x
=
0
;
x
<
size
;
x
++
){
y
=
x
;
diagonal1
=
matrix2
[
x
][
y
]
*
diagonal1
;
}
for
(
x
=
0
;
x
<
size
;
x
++
){
y
=
size
-
1
-
x
;
diagonal2
=
matrix2
[
x
][
y
]
*
diagonal2
;
}
byhand
=
diagonal1
+
diagonal2
;
printf
(
"%d
\n
"
,
byhand
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment