Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
matjul
/
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
470dcad1
authored
6 years ago
by
matjul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
97e66cf0
master
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
155 additions
and
0 deletions
lab4task2fixed.c
lab4task2fixed.c
0 → 100644
View file @
470dcad1
#include <stdio.h>
#include <string.h>
int
main
(){
int
i
;
int
j
;
int
x
;
printf
(
"Choose the size of the matrices: "
);
scanf
(
"%d"
,
&
x
);
i
=
x
;
j
=
x
;
int
matrice1
[
x
][
x
];
printf
(
"Now fill the rows of the first matrice with the numbers:
\n
"
);
for
(
i
=
0
;
i
<
x
;
i
++
)
{
for
(
j
=
0
;
j
<
x
;
j
++
)
{
scanf
(
"%d"
,
&
matrice1
[
i
][
j
]);
}
}
printf
(
"the first matrice is:
\n
"
);
for
(
i
=
0
;
i
<
x
;
i
++
)
{
for
(
j
=
0
;
j
<
x
;
j
++
)
{
printf
(
"%d, "
,
matrice1
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
int
matrice2
[
x
][
x
];
printf
(
"Now fill the rows of the second matrice with the numbers:
\n
"
);
for
(
i
=
0
;
i
<
x
;
i
++
)
{
for
(
j
=
0
;
j
<
x
;
j
++
)
{
scanf
(
"%d"
,
&
matrice2
[
i
][
j
]);
}
}
printf
(
"The second matrice is:
\n
"
);
for
(
i
=
0
;
i
<
x
;
i
++
)
{
for
(
j
=
0
;
j
<
x
;
j
++
)
{
printf
(
"%d, "
,
matrice2
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
int
sumOfMatrices
[
x
][
x
];
printf
(
"The sum of the matrices is:
\n
"
);
for
(
i
=
0
;
i
<
x
;
i
++
){
for
(
j
=
0
;
j
<
x
;
j
++
){
sumOfMatrices
[
i
][
j
]
=
matrice1
[
i
][
j
]
+
matrice2
[
i
][
j
];
printf
(
"%d, "
,
sumOfMatrices
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
int
diffOfMatrices
[
x
][
x
];
printf
(
"The difference of the matrices is:
\n
"
);
for
(
i
=
0
;
i
<
x
;
i
++
){
for
(
j
=
0
;
j
<
x
;
j
++
){
diffOfMatrices
[
i
][
j
]
=
matrice1
[
i
][
j
]
-
matrice2
[
i
][
j
];
printf
(
"%d, "
,
diffOfMatrices
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
int
array1
[
x
];
int
array2
[
x
];
for
(
i
=
0
;
i
<
x
;
i
++
){
for
(
j
=
0
;
j
<
x
;
j
++
){
if
(
i
==
j
){
array1
[
i
]
=
matrice1
[
i
][
j
];
printf
(
"%d, "
,
array1
[
i
]);
}
if
(
i
+
j
==
x
-
1
){
array2
[
i
]
=
matrice1
[
i
][
j
];
}
}
}
printf
(
"
\n
"
);
for
(
i
=
0
;
i
<
x
;
i
++
){
printf
(
"%d, "
,
array2
[
i
]);
}
int
sumOfFirstDiagOfFirstMatrice
=
1
;
for
(
i
=
0
;
i
<
3
;
i
++
){
sumOfFirstDiagOfFirstMatrice
*=
array1
[
i
];
}
printf
(
"The sum of the first diagonal
\n
"
);
printf
(
"%d, "
,
sumOfFirstDiagOfFirstMatrice
);
int
sumOfSecondDiagOfFirstMatrice
=
1
;
for
(
i
=
0
;
i
<
3
;
i
++
){
sumOfSecondDiagOfFirstMatrice
*=
array2
[
i
];
}
printf
(
"The sum of the second diagonal
\n
"
);
printf
(
"%d, "
,
sumOfSecondDiagOfFirstMatrice
);
int
sumOfTwoDiagOfFirstMatrice
;
sumOfTwoDiagOfFirstMatrice
=
sumOfFirstDiagOfFirstMatrice
+
sumOfSecondDiagOfFirstMatrice
;
printf
(
"The sum of the two diagonals
\n
"
);
printf
(
"%d
\n
"
,
sumOfTwoDiagOfFirstMatrice
);
int
productOfMain1
=
1
;
int
productOfOff1
=
1
;
int
productOfMain2
=
1
;
int
productOfOff2
=
1
:
for
(
i
=
0
;
i
<
x
;
i
++
){
productOfMain1
*=
matrice1
[
i
][
i
];
productOfMain2
*=
matrice2
[
i
][
i
];
productOfOff1
*=
matrice1
[
i
][
x
-
1
-
i
];
productofOff2
*=
matrice2
[
i
][
x
-
1
-
i
];
}
sum1
=
productOfMain1
+
productOfOff1
;
sum2
=
productOfMain2
+
productOfOff2
;
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