Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
trkall
/
iag0582
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
cf6031aa
authored
7 years ago
by
trkall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eksam
parent
8c96e8fb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
0 deletions
eksam/eksam.c
eksam/eksamtxt.txt
eksam/l6pp.txt
eksam/eksam.c
0 → 100644
View file @
cf6031aa
#include <stdio.h>
#include <stdlib.h>
/**
annab m2lu muutujale newContents, suurusega stackElementT suuruse korrutatud muutujaga maxSize
kui mlu andmine ei t66ta, kirjutatakse faili, mille nimi koodis on stderr, hunniku x'e ning pannakse fail kinni s6numiga 1
**/
double
*
sisselugemine
(
double
*
,
int
*
,
char
*
);
double
*
arvutus
(
double
*
,
double
*
,
int
);
void
v2ljastus
(
double
*
,
int
,
char
*
);
int
main
(
void
)
{
double
*
A
=
(
double
*
)
malloc
(
sizeof
(
double
));
double
*
B
=
(
double
*
)
malloc
(
sizeof
(
double
));
int
m
;
char
*
FileName
=
"eksamtxt.txt"
;
char
*
FileName2
=
"l6pp.txt"
;
A
=
sisselugemine
(
A
,
&
m
,
FileName
);
B
=
arvutus
(
A
,
B
,
m
);
v2ljastus
(
B
,
m
,
FileName2
);
free
(
A
);
free
(
B
);
return
0
;
}
double
*
sisselugemine
(
double
*
A
,
int
*
m
,
char
*
FileName
)
{
FILE
*
input
;
int
i
=
0
;
double
buf
;
double
*
temp
;
input
=
fopen
(
FileName
,
"r"
);
while
(
fscanf
(
input
,
"%lf"
,
&
buf
)
!=
EOF
)
{
temp
=
(
double
*
)
realloc
(
A
,
sizeof
(
double
)
*
(
i
+
1
));
if
(
temp
==
NULL
)
{
printf
(
"Memory Allocation Failed"
);
fclose
(
input
);
free
(
A
);
exit
(
1
);
}
A
=
temp
;
*
(
A
+
i
)
=
buf
;
i
++
;
}
*
m
=
i
;
fclose
(
input
);
return
A
;
}
double
*
arvutus
(
double
*
A
,
double
*
B
,
int
m
)
{
int
i
,
n
;
double
temp
=
0
;
for
(
i
=
0
;
i
<
m
;
i
++
)
{
temp
+=
*
(
A
+
i
);
}
*
(
B
+
0
)
=
temp
;
for
(
n
=
1
;
n
<
m
-
1
;
n
++
)
{
B
=
(
double
*
)
realloc
(
B
,
sizeof
(
double
)
*
(
n
+
1
));
*
(
B
+
n
)
=
*
(
B
+
(
n
-
1
))
-
*
(
A
+
n
);
}
return
B
;
}
void
v2ljastus
(
double
*
B
,
int
m
,
char
*
FileName
)
{
FILE
*
output
;
int
i
;
output
=
fopen
(
FileName
,
"w"
);
for
(
i
=
0
;
i
<
m
-
1
;
i
++
)
{
fprintf
(
output
,
"%d)
\t
%0.2lf
\n
"
,
i
+
1
,
*
(
B
+
i
));
}
fclose
(
output
);
}
This diff is collapsed.
Click to expand it.
eksam/eksamtxt.txt
0 → 100644
View file @
cf6031aa
4.5
-23
128
55
0.77
13
-7.5
0.85
This diff is collapsed.
Click to expand it.
eksam/l6pp.txt
0 → 100644
View file @
cf6031aa
1) 171.62
2) 194.62
3) 66.62
4) 11.62
5) 10.85
6) -2.15
7) 5.35
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