Skip to content

Commit

Permalink
Actually working! Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YorikasChopanos committed Mar 28, 2022
1 parent 20ae81a commit 22555a3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 51 deletions.
77 changes: 26 additions & 51 deletions c_tutorial.c
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 modified hornerCalculatorExe
Binary file not shown.

0 comments on commit 22555a3

Please sign in to comment.