Compare commits
25 Commits
Author | SHA1 | Date |
---|---|---|
array-in-a-matrix | 86979c9d54 | |
array-in-a-matrix | 5583e2ddb8 | |
array-in-a-matrix | 870de20e20 | |
array-in-a-matrix | 3d6877c822 | |
array-in-a-matrix | 97dbc9fb7b | |
array-in-a-matrix | 16e566bfa0 | |
array-in-a-matrix | 5fa84b93fb | |
array-in-a-matrix | 858990447e | |
array-in-a-matrix | 3bb69b067b | |
array-in-a-matrix | 56fa33af33 | |
array-in-a-matrix | 8180560937 | |
array-in-a-matrix | 366f728cf2 | |
array-in-a-matrix | c9a28180bd | |
array-in-a-matrix | 4721f63b25 | |
array-in-a-matrix | 9a04c7ff2b | |
array-in-a-matrix | d05cb38140 | |
Array in a Matrix | 33f9aff350 | |
array-in-a-matrix | 352f3a9472 | |
array-in-a-matrix | e90ab33dd8 | |
array-in-a-matrix | 533eb5243e | |
array-in-a-matrix | 51a1738e18 | |
array-in-a-matrix | 6de5afde59 | |
array-in-a-matrix | dc49dbf65b | |
array-in-a-matrix | eea5ee0e3f | |
array-in-a-matrix | 63559385e7 |
|
@ -50,3 +50,7 @@ modules.order
|
|||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# quadratic executable
|
||||
quadratic
|
||||
quadratic-tui
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# quadratic
|
||||
|
||||
Simple cli calculator that computes real and complex roots of a quadratic.
|
||||
<br>
|
||||
Make a project do one thing good rather than do alot that isn't. I learned from my past projects and the best way to code is to KISS.
|
||||
|
|
12
makefile
12
makefile
|
@ -1,2 +1,12 @@
|
|||
DESTDIR ?= /usr/bin
|
||||
|
||||
all:
|
||||
gcc quadratic.c -lm -Wall -O3 -o "bin-quadratic.out"
|
||||
gcc quadratic.c -lm -Wall -O3 -o "quadratic"
|
||||
cp quadratic-tui.sh quadratic-tui
|
||||
|
||||
install:
|
||||
install -Dm755 quadratic $(DESTDIR)/
|
||||
install -Dm755 quadratic-tui $(DESTDIR)/
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)/{quadratic,quadratic-tui}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/sh
|
||||
|
||||
ARG_A=$(whiptail --inputbox "Please enter the value for \"a\":" 10 50 --title "Quadratic Calculator" 3>&1 1>&2 2>&3)
|
||||
|
||||
exitstatus=$?
|
||||
if [ $exitstatus != 0 ]; then
|
||||
echo "User cancelled input."
|
||||
exit
|
||||
fi
|
||||
|
||||
ARG_B=$(whiptail --inputbox "Please enter the value for \"b\":" 10 50 --title "Quadratic Calculator" 3>&1 1>&2 2>&3)
|
||||
|
||||
exitstatus=$?
|
||||
if [ $exitstatus != 0 ]; then
|
||||
echo "User cancelled input."
|
||||
exit
|
||||
fi
|
||||
|
||||
ARG_C=$(whiptail --inputbox "Please enter the value for \"c\":" 10 50 --title "Quadratic Calculator" 3>&1 1>&2 2>&3)
|
||||
|
||||
exitstatus=$?
|
||||
if [ $exitstatus != 0 ]; then
|
||||
echo "User cancelled input."
|
||||
exit
|
||||
fi
|
||||
|
||||
quadratic $ARG_A $ARG_B $ARG_C
|
57
quadratic.c
57
quadratic.c
|
@ -1,47 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
int main(int num_arg, char **args)
|
||||
{
|
||||
system("clear");
|
||||
printf("\n ~~ Quadratic Calculator ~~\n");
|
||||
printf(" ̲ ̲ ̲ ̲ ̲ ̲\n");
|
||||
printf(" ̲-̲b̲±̲√̲b̲̲²̲̲-̲4̲a̲c̲\n");
|
||||
printf(" 2a\n\n");
|
||||
|
||||
double num_A, num_B, num_C;
|
||||
|
||||
printf("Please enter the value for \"a\":\n");
|
||||
scanf("%lf", &num_A);
|
||||
printf("Please enter the value for \"b\":\n");
|
||||
scanf("%lf", &num_B);
|
||||
printf("Please enter the value for \"c\":\n");
|
||||
scanf("%lf", &num_C);
|
||||
|
||||
double radical = pow(num_B, 2) + (-4 * num_A * num_C);
|
||||
printf("\nUnder the radical: %f\n", radical);
|
||||
if (radical < 0.0)
|
||||
if (num_arg <= 1)
|
||||
{
|
||||
// roots are complex
|
||||
printf("Roots are complex.\n");
|
||||
|
||||
double real_part = (-num_B) / (2 * num_A);
|
||||
double imaginary_part = sqrt(radical * -1.0) / (2 * num_A);
|
||||
|
||||
printf("The zeros are: %f+%fi and %f-%fi.\n", real_part, imaginary_part, real_part, imaginary_part);
|
||||
system("quadratic-tui"); // make sure it is in PATH along with "quadratic" bin
|
||||
}
|
||||
else
|
||||
{
|
||||
// roots are real
|
||||
printf("Roots are real.\n");
|
||||
num_A = atof(args[1]);
|
||||
num_B = atof(args[2]);
|
||||
num_C = atof(args[3]);
|
||||
|
||||
double numerator_1 = (-num_B) + sqrt(radical);
|
||||
double numerator_2 = (-num_B) - sqrt(radical);
|
||||
double zero_1_ptr = numerator_1 / (2 * num_A);
|
||||
double zero_2_ptr = numerator_2 / (2 * num_A);
|
||||
double radical = pow(num_B, 2) + (-4 * num_A * num_C);
|
||||
|
||||
printf("The zeros are: %f and %f.\n", zero_1_ptr, zero_2_ptr);
|
||||
if (radical < 0.0)
|
||||
{
|
||||
// roots are complex
|
||||
double real_part = (-num_B) / (2 * num_A);
|
||||
double imaginary_part = sqrt(radical * -1.0) / (2 * num_A);
|
||||
|
||||
printf("%g+%gi\t %g-%gi\n", real_part, imaginary_part, real_part, imaginary_part);
|
||||
}
|
||||
else
|
||||
{
|
||||
// roots are real
|
||||
double numerator_1 = (-num_B) + sqrt(radical);
|
||||
double numerator_2 = (-num_B) - sqrt(radical);
|
||||
double zero_1_ptr = numerator_1 / (2 * num_A);
|
||||
double zero_2_ptr = numerator_2 / (2 * num_A);
|
||||
|
||||
printf("%g\t %g\n", zero_1_ptr, zero_2_ptr);
|
||||
};
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue