-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20ae81a
commit 22555a3
Showing
2 changed files
with
26 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,67 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
// gcc -Wall c_tutorial.c -o hornerCalculatorExe | ||
// ./hornerCalculatorExe | ||
|
||
// void horner(int coefficient[], int divisor[z], int polynomialDegree, int | ||
// newCoefficient[]) { | ||
// for(int i = 2; i <= polynomialDegree; i++) { | ||
// newCoefficient[i] = (newCoefficient[i-1]*divisor[z]) + | ||
// coefficient[i]; printf("%d\n", newCoefficient[i]); | ||
// }; | ||
|
||
// }; | ||
|
||
int getPolynomialDegree() | ||
{ | ||
int getPolynomialDegree() { | ||
int polynomialDegree; | ||
printf("Insert degree of polynomial: "); | ||
scanf("%d", &polynomialDegree); | ||
return polynomialDegree; | ||
}; | ||
|
||
int getCoefficients() | ||
{ | ||
int getCoefficients() { | ||
int coefficient; | ||
printf( | ||
"Insert coefficients in the order of decreasing polynomial exponents: "); | ||
scanf("%d", &coefficient); | ||
return coefficient; | ||
}; | ||
|
||
int getStableTerm() | ||
{ | ||
int getStableTerm() { | ||
int stableTerm; | ||
printf("Insert stable term: "); | ||
scanf("%d", &stableTerm); | ||
return stableTerm; | ||
}; | ||
|
||
int main() | ||
{ | ||
int main() { | ||
|
||
int polynomialDegree = getPolynomialDegree(); | ||
int coefficients[polynomialDegree]; | ||
for (int i = 0; i < polynomialDegree; i++) | ||
{ | ||
for (int i = 0; i < polynomialDegree; i++) { | ||
coefficients[i] = getCoefficients(); | ||
}; | ||
|
||
int stableTerm = getStableTerm(); | ||
int divisor[stableTerm]; | ||
int divisorCounter = 1; | ||
for (int i = 0; i <= stableTerm * 2; i += 2) | ||
{ | ||
for (int i = 0; i <= stableTerm * 2; i += 2) { | ||
if (stableTerm % divisorCounter == 0) { | ||
divisor[i] = divisorCounter; | ||
divisor[i + 1] = divisorCounter * -1; | ||
printf("%d\n", divisor[i]); | ||
printf("%d\n", divisor[i + 1]); | ||
// printf("%d\n", divisor[i]); | ||
// printf("%d\n", divisor[i + 1]); | ||
}; | ||
divisorCounter++; | ||
}; | ||
int newCoefficients[polynomialDegree]; | ||
int newDivisor; | ||
int remainder; | ||
newCoefficients[0] = coefficients[0]; | ||
for (int i = 1; i <= polynomialDegree; i++) | ||
{ | ||
newCoefficients[i] = (newCoefficients[i-1]*divisor[0]) + coefficients[i]; | ||
printf("%d\n", newCoefficients[i]); | ||
for (divisorCounter = 0; | ||
divisorCounter <= sizeof(divisor) / sizeof(divisor[0]); | ||
divisorCounter++) { | ||
for (int i = 1; i <= polynomialDegree - 1; i++) { | ||
newCoefficients[i] = | ||
(newCoefficients[i - 1] * divisor[divisorCounter]) + coefficients[i]; | ||
remainder = (newCoefficients[2] * divisor[divisorCounter]) + stableTerm; | ||
}; | ||
if (remainder == 0) { | ||
printf("Your equation is solved! Here are the coefficients: \n"); | ||
for (int i = 0; | ||
i < (sizeof(newCoefficients) / sizeof(newCoefficients[0])); i++) { | ||
printf("%d ", newCoefficients[i]); | ||
}; | ||
break; | ||
}; | ||
}; | ||
|
||
// int remainderIsZero = 0; | ||
// int newCoefficient[polynomialDegree]; | ||
// newCoefficient[0] = coefficients[0]; | ||
// newCoefficient[1] = (coefficients[0]*divisor[0]) + coefficients[1]; | ||
// int z = 0; | ||
// int divisorArraySize = sizeof(divisor)/sizeof(divisor[0]); | ||
// int *pCoefficient; | ||
// pCoefficient = &coefficients[i]; | ||
// int *pDivisor; | ||
// pDivisor = &divisor[z]; | ||
// int *pNewCoefficient; | ||
// pNewCoefficient = &newCoefficient[i]; | ||
// while( z < divisorArraySize && remainderIsZero == 0 ) { | ||
// horner(pCoefficient, pDivisor, polynomialDegree, pNewCoefficient); | ||
// if (newCoefficient[divisorArraySize] == 0){ | ||
// remainderIsZero = 1; | ||
// } else { | ||
// z++; | ||
// }; | ||
// }; | ||
}; |
Binary file not shown.