Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
viakul
/
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
7ecbb37c
authored
Oct 15, 2018
by
viakul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
9609658c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
0 deletions
lab6/2.c
lab6/2.c
0 → 100644
View file @
7ecbb37c
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int
findA
(
char
*
equation
);
int
findB
(
char
*
equation
);
int
findC
(
char
*
equation
);
int
findDiscriminant
(
int
B
,
int
C
);
int
main
()
{
char
string
[
100
];
int
a
;
int
b
;
int
c
;
scanf
(
"%s"
,
string
);
a
=
findA
(
string
);
printf
(
"A value %d
\n
"
,
a
);
b
=
findB
(
string
);
printf
(
"B value %d
\n
"
,
b
);
c
=
findC
(
string
);
printf
(
"C value %d"
,
c
);
return
0
;
}
int
findA
(
char
*
equation
){
int
i
=
0
;
char
A
[
100
]
=
{
""
};
while
(
1
){
if
(((
equation
[
i
]
>
47
)
&&
(
equation
[
i
]
<
58
))
||
(
equation
[
i
]
==
'x'
)){
if
(
equation
[
i
]
==
'x'
){
break
;
}
else
{
strcat
(
A
,
&
equation
[
i
]);
i
++
;
}
A
[
i
]
=
'\0'
;
return
atoi
(
A
);
}
else
{
printf
(
"you have a mistake in user input. "
);
break
;
}
}
}
int
findB
(
char
*
equation
){
int
i
=
0
;
char
B
[
100
]
=
{
""
};
while
(
1
){
if
(
equation
[
i
]
==
'x'
){
break
;
}
i
++
;
}
while
(
1
){
if
(
equation
[
i
]
==
'+'
){
break
;
}
else
if
(
equation
[
i
]
==
'-'
)
{
strncat
(
B
,
&
equation
[
i
],
1
);
break
;
}
i
++
;
}
i
++
;
while
(
1
){
if
(
equation
[
i
]
==
'x'
){
break
;
}
else
{
strncat
(
B
,
&
equation
[
i
],
1
);
i
++
;
}
B
[
i
]
=
'\0'
;
}
return
atoi
(
B
);
}
int
findC
(
char
*
equation
){
int
i
=
0
;
char
C
[
100
]
=
{
""
};
int
m
=
0
;
while
(
1
){
if
(
equation
[
i
]
==
'x'
){
m
++
;
}
if
(
m
==
2
){
break
;
}
i
++
;
}
i
=
i
+
1
;
strcat
(
C
,
&
equation
[
i
]);
C
[
i
]
=
'\0'
;
return
atoi
(
C
);
}
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