Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
aostap
/
KT2programmeerimine2Anastasiia
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
ca1b1ab6
authored
a year ago
by
aostap
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parents
master
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
0 deletions
kood.c
kood.c
0 → 100644
View file @
ca1b1ab6
//Programmeerimine 2, kodutöö 2 , variant 21
#include <stdio.h>
#include <math.h>
int
sisestus1
(
char
[]);
// e
int
sisestus2
(
char
[]);
// x
double
calculate_A
(
int
,
double
);
void
valjastus
(
FILE
*
,
int
,
double
[]);
int
main
()
{
double
A
[
15
];
double
X
=
sisestus1
(
"Sisesta reaalarvuline X :
\n
"
);
double
e
=
sisestus2
(
"Sisesta reaalarvuline E :
\n
"
);
int
L
=
1
;
A
[
0
]
=
X
;
while
(
L
<
15
&&
fabs
(
A
[
L
-
1
]
-
A
[
L
-
2
])
>
e
)
{
A
[
L
]
=
calculate_A
(
L
+
1
,
X
);
L
++
;
}
printf
(
"A elementide arv: %d
\n
"
,
L
);
FILE
*
fp
;
//faili avamine ja kontroll kas on see olemas
fp
=
fopen
(
"F.txt"
,
"w"
);
if
(
fp
==
NULL
){
printf
(
"File 'F1.txt' not found"
);
return
1
;}
valjastus
(
fp
,
L
,
A
);
fclose
(
fp
);
// faili kinni panemine
return
0
;
}
int
sisestus1
(
char
text
[])
// E sisestus
{
float
nr
;
do
{
printf
(
"%s"
,
text
);
scanf
(
"%f"
,
&
nr
);
}
while
(
nr
<
0
||
nr
>
1
);
// 0<e<1
return
nr
;
}
int
sisestus2
(
char
text
[])
//X-i sisestus
{
float
arv
;
do
{
printf
(
"%s"
,
text
);
scanf
(
"%f"
,
&
arv
);
}
while
(
fabs
(
arv
)
>
0
);
//|x|<1
return
arv
;
}
double
calculate_A
(
int
L
,
double
X
)
{
if
(
L
==
1
)
{
return
X
;
}
double
sum
=
0
;
for
(
int
i
=
1
;
i
<=
L
-
1
;
i
++
)
{
sum
+=
((
2
*
i
-
1
)
*
calculate_A
(
i
,
X
));
}
return
-
1
.
0
/
L
*
pow
(
X
,
2
*
L
-
3
)
*
sum
;
}
void
valjastus
(
FILE
*
fp
,
int
L
,
double
A
[]){
fprintf
(
fp
,
"A elemintide arv %d
\n
"
,
L
);
for
(
int
i
=
0
;
i
<
L
;
i
++
)
{
fprintf
(
fp
,
"A[%d]
\t
%lf
\n
"
,
i
+
1
,
A
[
i
]);
}}
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