Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
kmicha
/
Tallinna-Veehaarde-Projket
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
23d53542
authored
Apr 15, 2024
by
kmicha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Version 2 projekti C koodist
parent
65b953e6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
155 additions
and
0 deletions
Proge failid/Ver 2/Main.c
Proge failid/Ver 2/Main.c
0 → 100644
View file @
23d53542
/*
Ver 3
------
Html/javascriptist tuleb käsk/sisetus punktist X(joe ID):
1)html(X) -> C(N) -> html
2)html(X) -> C(vahemaa) -> html
3)html(X) -> C(kiirus) -> html
4)html(N, vahemaa, kiirus) -> html(aeg)
5)Profit
*/
#include <stdio.h>
#include <stdlib.h>
typedef
struct
{
int
ID
;
int
suubumis_ID
;
double
pikkus
;
double
kiirus
;
}
jogi
;
int
JogedeArv
(
int
);
double
Vahemaa
(
int
);
double
Kiirus
(
int
);
void
fileLugemine
(
jogi
[
20
]);
int
main
(){
int
ID
=
11
;
int
jogedeArv
;
double
vahemaa
;
double
kiirus
;
jogedeArv
=
JogedeArv
(
ID
);
vahemaa
=
Vahemaa
(
ID
);
kiirus
=
Kiirus
(
ID
);
printf
(
"ID: %d
\n
Punktide arv: %d
\n
Vahemaa: %.2f
\n
Kiirus: %.2f"
,
ID
,
jogedeArv
,
vahemaa
,
kiirus
);
return
0
;
}
//Leiab mitu erinevat mõõte punkti on valitud punkti ja ülemiste vahel
int
JogedeArv
(
int
ID
){
//printf("JogedeArv algus\n");
int
tempID
=
0
;
int
i
=
ID
;
int
N
=
0
;
jogi
joed
[
20
];
fileLugemine
(
joed
);
for
(
N
=
0
;
N
<
20
;
N
++
){
/*printf("\nhetke id: %d\n",i);
printf("hetke id: %d\n",joed[i].ID);
printf("hetke suubumisID: %d\n",joed[i].suubumis_ID);
printf("hetke tempID: %d\n\n",tempID);
*/
if
(
joed
[
i
].
ID
==
joed
[
i
].
suubumis_ID
){
return
N
;
}
tempID
=
joed
[
i
].
suubumis_ID
;
i
=
tempID
;
}
//printf("JogedeArv lopp\n");
return
N
;
}
double
Vahemaa
(
int
ID
){
//printf("Vahemaa algus\n");
int
i
=
ID
;
double
vahemaa
=
0
;
jogi
joed
[
20
];
fileLugemine
(
joed
);
while
(
joed
[
i
].
ID
!=
joed
[
i
].
suubumis_ID
){
vahemaa
+=
joed
[
i
].
pikkus
;
i
=
joed
[
i
].
suubumis_ID
;
}
//printf("Vahemaa lopp\n");
return
vahemaa
;
}
double
Kiirus
(
int
ID
){
//printf("Kiirus algus\n");
int
i
=
ID
;
double
kiirus
=
0
;
jogi
joed
[
20
];
fileLugemine
(
joed
);
while
(
joed
[
i
].
ID
!=
joed
[
i
].
suubumis_ID
){
kiirus
+=
joed
[
i
].
kiirus
;
i
=
joed
[
i
].
suubumis_ID
;
}
//printf("Kiirus lopp\n");
return
kiirus
;
}
void
fileLugemine
(
jogi
joed
[
20
]){
//printf("fileLugemine algus\n");
int
i
=
0
;
FILE
*
F1
;
F1
=
fopen
(
"andmed.txt"
,
"r"
);
while
(
fscanf
(
F1
,
"%d %d %lf %lf"
,
&
joed
[
i
].
ID
,
&
joed
[
i
].
suubumis_ID
,
&
joed
[
i
].
pikkus
,
&
joed
[
i
].
kiirus
)
!=
EOF
){
/* printf("%d %d %d %.2lf %.2lf\n",
i,
joed[i].ID,
joed[i].suubumis_ID,
joed[i].pikkus,
joed[i].kiirus);
*/
i
++
;
}
fclose
(
F1
);
//printf("fileLugemine lopp\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