Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
karlki
/
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
78c02a1f
authored
Nov 21, 2017
by
karlki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
raha automaat
parent
151f301d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
Praktikum12/praktikum12.c
Praktikum12/praktikum12.c
0 → 100644
View file @
78c02a1f
#include <stdio.h>
#include <math.h>
int
arvSisse
(
char
*
);
int
Kontroll
(
int
,
int
);
void
kupyyrid
(
int
[][
2
],
int
,
int
[]);
void
tulValja
(
int
[][
2
],
int
,
int
[]);
int
main
(
void
)
{
int
kupKogus
;
kupKogus
=
arvSisse
(
"Mitu erinevat kupyyri"
);
int
valj
[
kupKogus
];
int
kupyyridKogus
[
kupKogus
][
2
];
kupyyrid
(
kupyyridKogus
,
kupKogus
,
valj
);
tulValja
(
kupyyridKogus
,
kupKogus
,
valj
);
return
0
;
}
int
arvSisse
(
char
*
lause
)
{
int
kogus
=
0
;
printf
(
"%s
\n
"
,
lause
);
scanf
(
"%d"
,
&
kogus
);
return
kogus
;
}
void
kupyyrid
(
int
kupyyrid
[][
2
],
int
kupKogus
,
int
valj
[])
{
int
k
=
0
;
int
i
;
valj
[
kupKogus
];
for
(
i
=
0
;
i
<
kupKogus
;
i
++
){
valj
[
i
]
=
0
;
}
while
(
k
<
kupKogus
)
{
kupyyrid
[
k
][
0
]
=
arvSisse
(
"Sisesta kupyyr"
);
kupyyrid
[
k
][
1
]
=
arvSisse
(
"Sisesta kupyyri kogus"
);
k
++
;
}
int
kogus
=
arvSisse
(
"Sisesta kogus"
);
while
(
kogus
>
0
)
{
if
(
kogus
-
kupyyrid
[
k
][
0
]
>
-
kupyyrid
[
kupKogus
-
1
][
0
])
{
if
(
kupyyrid
[
k
][
1
]
>
0
)
{
// kupyyre on piisavalt
kogus
-=
kupyyrid
[
k
][
0
];
valj
[
k
]
++
;
printf
(
"%d
\n
"
,
kupyyrid
[
k
][
0
]);
if
(
k
>
0
)
{
k
--
;
}
}
else
{
// kupyyre ei j2tku
if
(
k
<
kupKogus
)
{
k
++
;
}
else
{
printf
(
"Rahad on otsas!
\n
"
);
printf
(
"%d
\n
"
,
kogus
);
kogus
=
-
1
;
}
}
}
else
if
(
k
<
kupKogus
)
{
k
++
;
}
}
}
void
tulValja
(
int
kupyyrid
[][
2
],
int
kupKogus
,
int
valj
[])
{
printf
(
"----------
\n
"
);
int
kogus
=
0
;
int
i
;
for
(
i
=
0
;
i
<
kupKogus
;
i
++
)
{
if
(
valj
[
i
]
>
0
)
{
printf
(
"%dx%d
\n
"
,
valj
[
i
],
kupyyrid
[
i
][
0
]);
kogus
+=
valj
[
i
]
*
kupyyrid
[
i
][
0
];
}
}
printf
(
"----------
\n
"
);
printf
(
"%d
\n
"
,
kogus
);
}
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