-
Notifications
You must be signed in to change notification settings - Fork 0
/
factor10.c
58 lines (52 loc) · 1.17 KB
/
factor10.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Program Name : factor10.c
* Discription : Factors one negative (b) and one positive (c) number
* Author : Joshua Pena
* Date : 15|01|14
*/
#include <stdio.h>
// Function Prototypes
void function10(int, int);
// Function Definitions
void function10(additionGoal, multiplyGoal) {
int check = 0;
int impossible = 0;
int num1 = 0;
int num2 = 0;
int multiplyCheck = 0;
int additionCheck = 0;
int possibleCheck;
while (multiplyCheck != 1) {
while (additionCheck != 1) {
check = num1 + num2;
if (check > additionGoal) {
num1--;
} else if (num2 < -multiplyGoal) {
impossible = 1;
additionCheck = 1;
} else if (check < additionGoal) {
num1 = 0;
num2--;
} else if (check == additionGoal) {
additionCheck = 1;
}
}
check = num1 * num2;
if (check == multiplyGoal) {
multiplyCheck = 1;
} else {
additionCheck = 0;
num1 = 0;
num2--;
}
if (impossible == 1) {
multiplyCheck = 1;
}
}
if (impossible == 0) {
printf("\n(x - %d) (x - %d)\n", -num1, -num2);
} else {
printf("\nNot Possible\n");
}
return;
}