Compare commits
25 commits
Author | SHA1 | Date | |
---|---|---|---|
86979c9d54 | |||
5583e2ddb8 | |||
870de20e20 | |||
3d6877c822 | |||
97dbc9fb7b | |||
16e566bfa0 | |||
5fa84b93fb | |||
858990447e | |||
array-in-a-matrix | 3bb69b067b | ||
56fa33af33 | |||
8180560937 | |||
366f728cf2 | |||
c9a28180bd | |||
4721f63b25 | |||
9a04c7ff2b | |||
d05cb38140 | |||
33f9aff350 | |||
352f3a9472 | |||
e90ab33dd8 | |||
533eb5243e | |||
51a1738e18 | |||
6de5afde59 | |||
dc49dbf65b | |||
eea5ee0e3f | |||
63559385e7 |
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -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}
|
||||
|
|
27
quadratic-tui.sh
Executable file
27
quadratic-tui.sh
Executable file
|
@ -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
|
35
quadratic.c
35
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);
|
||||
if (num_arg <= 1)
|
||||
{
|
||||
system("quadratic-tui"); // make sure it is in PATH along with "quadratic" bin
|
||||
}
|
||||
else
|
||||
{
|
||||
num_A = atof(args[1]);
|
||||
num_B = atof(args[2]);
|
||||
num_C = atof(args[3]);
|
||||
|
||||
double radical = pow(num_B, 2) + (-4 * num_A * num_C);
|
||||
printf("\nUnder the radical: %f\n", radical);
|
||||
|
||||
if (radical < 0.0)
|
||||
{
|
||||
// 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);
|
||||
printf("%g+%gi\t %g-%gi\n", real_part, imaginary_part, real_part, imaginary_part);
|
||||
}
|
||||
else
|
||||
{
|
||||
// roots are real
|
||||
printf("Roots are real.\n");
|
||||
|
||||
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("The zeros are: %f and %f.\n", zero_1_ptr, zero_2_ptr);
|
||||
printf("%g\t %g\n", zero_1_ptr, zero_2_ptr);
|
||||
};
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue