Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
tranvu
/
iax583
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
46596508
authored
Oct 08, 2018
by
tranvu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lab 6 tasks
parent
de8eab89
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
0 deletions
Lab 6/main.c
Lab 6/uml shit.png
Lab 6/main.c
0 → 100644
View file @
46596508
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
char
*
getInput
();
char
*
getElement
();
int
main
()
{
char
*
function
;
function
=
getInput
();
int
funSize
=
strlen
(
function
)
+
1
;
char
*
a
;
char
*
b
;
char
*
c
;
a
=
getElement
(
function
);
int
startB
=
strlen
(
a
)
+
4
;
char
newFunc
[
funSize
];
int
location
=
0
;
for
(
int
i
=
startB
-
1
;
i
<
funSize
;
i
++
)
{
newFunc
[
location
++
]
=
function
[
i
];
}
b
=
getElement
(
newFunc
);
int
startC
=
strlen
(
b
)
+
1
+
startB
;
location
=
0
;
for
(
int
i
=
startC
-
1
;
i
<
funSize
;
i
++
)
{
newFunc
[
location
++
]
=
function
[
i
];
}
c
=
getElement
(
newFunc
);
int
A
=
atoi
(
a
);
int
B
=
atoi
(
b
);
int
C
=
atoi
(
c
);
float
result1
=
(
-
B
+
sqrt
(
pow
(
B
,
2
)
-
4
*
A
*
C
))
/
(
2
*
A
);
float
result2
=
(
-
B
-
sqrt
(
pow
(
B
,
2
)
-
4
*
A
*
C
))
/
(
2
*
A
);
if
(
!
isnan
(
result1
))
printf
(
"Result 1: %f
\n
"
,
result1
);
else
printf
(
"Result 1 is not real
\n
"
);
if
(
!
isnan
(
result2
))
printf
(
"Result 2: %f
\n
"
,
result2
);
else
printf
(
"Result 2 is not real
\n
"
);
free
(
function
);
free
(
a
);
free
(
b
);
free
(
c
);
return
(
EXIT_SUCCESS
);
}
char
*
getElement
(
char
function
[])
{
char
*
element
;
int
funSize
=
strlen
(
function
);
int
size
=
1
,
location
=
0
;
element
=
malloc
(
size
*
sizeof
(
char
));
for
(
int
i
=
0
;
i
<
funSize
;
i
++
)
{
if
(
function
[
i
]
!=
'x'
)
{
element
[
location
++
]
=
function
[
i
];
if
(
location
>
size
)
{
element
=
realloc
(
element
,
++
size
*
sizeof
(
char
));
}
}
else
{
element
[
location
]
=
'\0'
;
return
element
;
}
}
element
[
location
]
=
'\0'
;
return
element
;
}
char
*
getInput
()
{
int
size
=
9
;
char
*
function
;
function
=
malloc
(
size
*
sizeof
(
char
));
printf
(
"Please input function: "
);
char
c
;
int
location
=
0
;
while
((
c
=
getc
(
stdin
))
!=
10
)
{
function
[
location
++
]
=
c
;
if
(
location
>
size
)
{
function
=
realloc
(
function
,
++
size
*
sizeof
(
char
));
}
}
function
[
location
]
=
'\0'
;
return
function
;
}
\ No newline at end of file
Lab 6/uml shit.png
0 → 100644
View file @
46596508
25.3 KB
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