Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jürgen Hein
/
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
e211a80e
authored
Jan 15, 2025
by
Jürgen Hein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
cdcb8d06
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
123 additions
and
0 deletions
Eeleksam/Korvaldiagonaalid.c
Eeleksam/Korvaldiagonaalid.c
0 → 100644
View file @
e211a80e
/* Leida maatriksis S[n][n] kõrvaldiagonaali peal negatiivsete elementide
* summad ning positiivsete elementide korrutised ja salvestab
* need maatriksisse V[]. Maatriks S tuleb sisestada klaviatuurilt või
* täita juhuslike arvudega vahemikus -100...100 (kasutada saab valida)*/
#include <string.h>
#include <stdio.h>
#define max 10
//Prototüübid
int
MaatriksParameetrid
(
char
[]);
void
MaatriksSisestus
(
char
[],
int
,
int
[
max
][
max
]);
void
Negatiivsedsummad
(
int
,
int
[][
max
],
int
[]);
void
PositiivsedKorrutised
(
int
,
int
[][
max
],
int
[]);
void
UusMaatriks
(
int
,
int
[],
int
[],
int
[]);
void
Valjastus
(
int
[]);
int
main
(
void
)
{
int
n
=
MaatriksParameetrid
(
"Sisestada maatriksi mõõdud"
);
int
S
[
n
][
n
];
int
summad
[
n
];
int
korrutised
[
n
];
int
V
[
max
*
2
];
MaatriksSisestus
(
"Sisestada maatriks"
,
n
,
S
);
Negatiivsedsummad
(
n
,
S
,
summad
);
PositiivsedKorrutised
(
n
,
S
,
korrutised
);
UusMaatriks
(
n
,
summad
,
korrutised
,
V
);
Valjastus
(
V
);
return
0
;
}
int
MaatriksParameetrid
(
char
teade
[])
{
int
arv
;
do
{
printf
(
"%s
\n
"
,
teade
);
scanf
(
"%d"
,
&
arv
);
if
(
arv
<=
1
||
arv
>=
10
)
{
printf
(
"Sisestatud väärtus ei sobi, sisestage täisarv vahemikus 1...10."
);
}
}
while
(
arv
<=
1
||
arv
>=
10
);
return
arv
;
}
void
MaatriksSisestus
(
char
teade
[],
int
n
,
int
S
[
n
][
n
])
{
int
i
,
j
;
//järjenumbrid, scanf kontrolli muutuja
printf
(
"%s
\n
"
,
teade
);
for
(
i
=
0
;
i
<
n
;
i
++
)
//veergude tsükkel
{
for
(
j
=
0
;
j
<
n
;
j
++
)
//ridade tsükkel
{
printf
(
"Sisestada väärtus veerg [%d], rida [%d]"
,
i
,
j
);
scanf
(
"%d"
,
&
S
[
i
][
j
]);
}
}
}
void
Negatiivsedsummad
(
int
n
,
int
S
[][
max
],
int
summad
[])
{
int
i
;
int
j
;
for
(
i
=
0
;
i
<
n
;
i
++
)
//veergude tsükkel
{
summad
[
i
]
=
0
;
for
(
j
=
0
;
j
<
n
;
j
++
)
//ridade tsükkel
{
if
(
S
[
i
][
n
-
1
-
i
]
<
0
){
summad
[
i
]
=
summad
[
i
]
+
S
[
i
][
j
];
}
}
}
}
void
PositiivsedKorrutised
(
int
n
,
int
S
[
n
][
n
],
int
korrutised
[])
{
int
i
;
int
j
;
for
(
i
=
0
;
i
<
n
;
i
++
)
//veergude tsükkel
{
korrutised
[
i
]
=
0
;
for
(
j
=
0
;
j
<
n
;
j
++
)
//ridade tsükkel
{
if
(
S
[
i
][
n
-
1
-
i
]
>
0
){
korrutised
[
i
]
=
korrutised
[
i
]
*
S
[
i
][
j
];
}
}
}
}
void
UusMaatriks
(
int
n
,
int
summad
[],
int
korrutised
[],
int
V
[])
{
int
i
;
int
j
;
int
a
=
strlen
(
summad
);
int
b
=
strlen
(
korrutised
);
for
(
i
=
0
;
i
<
a
;
i
++
)
{
V
[
i
]
=
summad
[
i
];
}
for
(
j
=
i
;
j
<
a
+
b
;
j
++
)
{
V
[
j
]
=
korrutised
[
j
];
}
}
void
Valjastus
(
int
V
[])
{
int
i
;
int
n
;
n
=
strlen
(
V
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
printf
(
"%d"
,
V
[
i
]);
}
}
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