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
42997e23
authored
Oct 14, 2024
by
Jürgen Hein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
de31fc8a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
211 additions
and
0 deletions
Kodutöö 2/Kodutoo2MassiividLiitmine.c
Kodutöö 2/Kodutoo2MassiividLiitmine.c
0 → 100644
View file @
42997e23
/* Kodutöö 2. Variant 4.
/* Kodutöö 2. Variant 4.
* Sisestatakse kaks massiivi A (n,m) ja B (k,l).
* Ridade ja veergude arv reaalarvulised 1<=n<=10.
* Moodustatakse massiiv C - massivide summa.
* Massiiv C dimensioonid min(n,k) ja min(m,l).
* Massiiv C kuvatakse ridade kaupa.*/
#include <stdio.h>
//Prototüübid
int
SisestusN
();
int
SisestusM
();
int
SisestusK
();
int
SisestusL
();
int
SisestusCRida
(
int
,
int
);
int
SisestusCVeerg
(
int
,
int
);
void
MaatriksSisestus
(
int
,
int
,
int
,
int
,
double
[][
10
],
double
[][
10
]);
void
V
ä
ljastusAlgne
(
int
,
int
,
int
,
int
,
double
[][
10
],
double
[][
10
]);
void
MaatriksLiitmine
(
int
,
int
,
double
[][
10
],
double
[][
10
],
double
[][
10
]);
void
CV
ä
ljastus
(
int
,
int
,
double
[][
10
]);
int
main
(
void
)
{
int
n
=
SisestusN
();
int
m
=
SisestusM
();
int
k
=
SisestusK
();
int
l
=
SisestusL
();
double
A
[
n
][
m
];
double
B
[
k
][
l
];
int
CRida
=
SisestusCRida
(
n
,
k
);
int
CVeerg
=
SisestusCVeerg
(
m
,
l
);
double
C
[
CRida
][
CVeerg
];
MaatriksSisestus
(
n
,
m
,
l
,
k
,
A
,
B
);
V
ä
ljastusAlgne
(
n
,
m
,
l
,
k
,
A
,
B
);
MaatriksLiitmine
(
CRida
,
CVeerg
,
A
,
B
,
C
);
CV
ä
ljastus
(
CRida
,
CVeerg
,
C
);
return
0
;
}
//Sisestus
int
SisestusN
()
{
int
n
;
do
{
printf
(
"Sisestage A ridade arv
\n
"
);
scanf
(
"%d"
,
&
n
);
if
(
n
<=
1
||
n
>=
10
)
{
printf
(
"Sisestatud väärtus ei sobi, sisestage täisarv vahemikus 1...10."
);
}
}
while
(
n
<=
1
||
n
>=
10
);
return
n
;
}
int
SisestusM
()
{
int
m
;
do
{
printf
(
"Sisestage A veergude arv
\n
"
);
scanf
(
"%d"
,
&
m
);
if
(
m
<=
1
||
m
>=
10
)
{
printf
(
"Sisestatud väärtus ei sobi, sisestage täisarv vahemikus 1...10."
);
}
}
while
(
m
<=
1
||
m
>=
10
);
return
m
;
}
int
SisestusK
()
{
int
k
;
do
{
printf
(
"Sisestage B ridade arv
\n
"
);
scanf
(
"%d"
,
&
k
);
if
(
k
<=
1
||
k
>=
10
)
{
printf
(
"Sisestatud väärtus ei sobi, sisestage täisarv vahemikus 1...10."
);
}
}
while
(
k
<=
1
||
k
>=
10
);
return
k
;
}
int
SisestusL
()
{
int
l
;
do
{
printf
(
"Sisestage B veergude arv
\n
"
);
scanf
(
"%d"
,
&
l
);
if
(
l
<=
1
||
l
>=
10
)
{
printf
(
"Sisestatud väärtus ei sobi, sisestage täisarv vahemikus 1...10."
);
}
}
while
(
l
<=
1
||
l
>=
10
);
return
l
;
}
int
SisestusCRida
(
int
n
,
int
k
)
{
int
CRida
;
if
(
n
<
k
)
{
CRida
=
k
;
}
else
{
CRida
=
n
;
}
return
CRida
;
}
int
SisestusCVeerg
(
int
m
,
int
l
)
{
int
CVeerg
;
if
(
m
<
l
)
{
CVeerg
=
l
;
}
else
{
CVeerg
=
m
;
}
return
CVeerg
;
}
void
MaatriksSisestus
(
int
n
,
int
m
,
int
k
,
int
l
,
double
A
[][
m
],
double
B
[][
l
])
{
int
i
,
j
,
Kontroll
;
//järjenumbrid, scanf kontrolli muutuja
for
(
j
=
0
;
j
<
m
;
j
++
)
{
for
(
i
=
0
;
i
<
n
;
i
++
)
{
do
{
printf
(
"Sisestada väärtus A[%d][%d]"
,
i
,
j
);
Kontroll
=
scanf
(
"%lf"
,
&
A
[
i
][
j
]);
if
(
Kontroll
==
0
)
{
printf
(
"Sisestatud väärtus ei sobi, sisestage reaalarv"
);
scanf
(
"%*s"
);
//A[i][j] ei anta väärtust
}
}
while
(
Kontroll
==
0
);
//reaalarvu kontroll
}
}
for
(
j
=
0
;
j
<
l
;
j
++
)
{
for
(
i
=
0
;
i
<
k
;
i
++
)
{
do
{
printf
(
"Sisestada väärtus B[%d][%d]"
,
i
,
j
);
Kontroll
=
scanf
(
"%lf"
,
&
B
[
i
][
j
]);
if
(
Kontroll
==
0
)
{
printf
(
"Sisestatud väärtus ei sobi, sisestage reaalarv"
);
scanf
(
"%*s"
);
}
}
while
(
Kontroll
==
0
);
}
}
}
void
V
ä
ljastusAlgne
(
int
n
,
int
m
,
int
k
,
int
l
,
double
A
[][
m
],
double
B
[][
l
])
{
int
i
,
j
;
printf
(
"
\n
Sisestatud maatriks A:
\n
"
);
for
(
j
=
0
;
j
<
m
;
j
++
)
{
for
(
i
=
0
;
i
<
n
;
i
++
)
{
printf
(
"%lf "
,
A
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
printf
(
"
\n
Sisestatud maatriks B:
\n
"
);
for
(
j
=
0
;
j
<
l
;
j
++
)
{
for
(
i
=
0
;
i
<
k
;
i
++
)
{
printf
(
"%lf "
,
B
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
}
void
MaatriksLiitmine
(
int
CRida
,
int
CVeerg
,
double
A
[][
CVeerg
],
double
B
[][
CVeerg
],
double
C
[][
CVeerg
])
{
int
j
,
i
;
for
(
j
=
0
;
j
<
CVeerg
;
j
++
)
{
for
(
i
=
0
;
i
<
CRida
;
i
++
)
{
C
[
i
][
j
]
=
A
[
i
][
j
]
+
B
[
i
][
j
];
}
}
}
void
CV
ä
ljastus
(
int
CRida
,
int
CVeerg
,
double
C
[][
CVeerg
])
{
int
j
,
i
;
printf
(
"
\n
Maatriks C:
\n
"
);
for
(
j
=
0
;
j
<
CVeerg
;
j
++
)
{
for
(
i
=
0
;
i
<
CRida
;
i
++
)
{
printf
(
"%lf "
,
C
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
}
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