Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
chazog
/
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
8d85b1b4
authored
6 years ago
by
chazog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
e5b42365
master
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
138 additions
and
0 deletions
Lab4/Task2.c
Lab4/Task2.c
0 → 100644
View file @
8d85b1b4
#include <stdio.h>
int
main
()
{
int
matrix_size
;
int
value
;
int
product
=
1
;
int
product2
=
1
;
int
num
;
printf
(
"Please enter dimension of matrices: "
);
scanf
(
"%d"
,
&
matrix_size
);
int
array1
[
matrix_size
][
matrix_size
];
int
array2
[
matrix_size
][
matrix_size
];
// Values for first Matrix
printf
(
"Please enter values for the first matrix:
\n
"
);
for
(
int
i
=
0
;
i
<
matrix_size
;
i
++
)
{
for
(
int
j
=
0
;
j
<
matrix_size
;
j
++
)
{
printf
(
"Please enter value: "
);
scanf
(
"%d"
,
&
array1
[
i
][
j
]);
}
}
printf
(
"
\n
This is your first Matrix:
\n
"
);
for
(
int
i
=
0
;
i
<
matrix_size
;
i
++
)
{
for
(
int
j
=
0
;
j
<
matrix_size
;
j
++
)
{
printf
(
"%d, "
,
array1
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
printf
(
"
\n
"
);
// Values for second Matrix
printf
(
"Please enter values for the second matrix:
\n
"
);
for
(
int
i
=
0
;
i
<
matrix_size
;
i
++
)
{
for
(
int
j
=
0
;
j
<
matrix_size
;
j
++
)
{
printf
(
"Please enter value: "
);
scanf
(
"%d"
,
&
array2
[
i
][
j
]);
}
}
printf
(
"
\n
This is your second Matrix:
\n
"
);
for
(
int
i
=
0
;
i
<
matrix_size
;
i
++
)
{
for
(
int
j
=
0
;
j
<
matrix_size
;
j
++
)
{
printf
(
"%d, "
,
array2
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
printf
(
"
\n
"
);
// Add
printf
(
"The sum of the two matrices is:
\n
"
);
for
(
int
i
=
0
;
i
<
matrix_size
;
i
++
)
{
for
(
int
j
=
0
;
j
<
matrix_size
;
j
++
)
{
value
=
array1
[
i
][
j
]
+
array2
[
i
][
j
];
printf
(
"%d, "
,
value
);
}
printf
(
"
\n
"
);
}
printf
(
"
\n
"
);
// Difference
printf
(
"The Difference of the two matrices is:
\n
"
);
for
(
int
i
=
0
;
i
<
matrix_size
;
i
++
)
{
for
(
int
j
=
0
;
j
<
matrix_size
;
j
++
)
{
value
=
array1
[
i
][
j
]
-
array2
[
i
][
j
];
printf
(
"%d, "
,
value
);
}
printf
(
"
\n
"
);
}
printf
(
"
\n
"
);
// The sum of the multiplication of elements on the diagonals of the two matrices
printf
(
"The sum of the multiplication of elements on
\n
"
);
printf
(
"the diagonals of the two matrices is:
\n
"
);
printf
(
"First Matrix: "
);
for
(
int
i
=
0
;
i
<
matrix_size
;
i
++
)
{
for
(
int
j
=
0
;
j
<
matrix_size
;
j
++
)
{
if
(
i
==
j
)
{
product
*=
array1
[
i
][
j
];
}
}
}
num
=
matrix_size
-
1
;
for
(
int
i
=
0
;
i
<
matrix_size
;
i
++
)
{
product2
*=
array1
[
i
][
num
];
num
--
;
}
product
=
product
+
product2
;
printf
(
"%d
\n
"
,
product
);
product
=
1
;
product2
=
1
;
printf
(
"Second Matrix: "
);
for
(
int
i
=
0
;
i
<
matrix_size
;
i
++
)
{
for
(
int
j
=
0
;
j
<
matrix_size
;
j
++
)
{
if
(
i
==
j
)
{
product
*=
array2
[
i
][
j
];
}
}
}
num
=
matrix_size
-
1
;
for
(
int
i
=
0
;
i
<
matrix_size
;
i
++
)
{
product2
*=
array2
[
i
][
num
];
num
--
;
}
product
=
product
+
product2
;
printf
(
"%d"
,
product
);
return
0
;
}
This diff is collapsed.
Click to expand it.
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