Compare commits

...

8 commits
beta ... main

Author SHA1 Message Date
array-in-a-matrix 83505d30ae too abusious 2021-06-14 22:53:44 -04:00
array-in-a-matrix 5429d6c121 Merge branch 'main' of https://github.com/array-in-a-matrix/cli-calculator 2021-06-14 22:51:02 -04:00
array-in-a-matrix 7901a3a579 entry added 2021-06-14 22:50:11 -04:00
array-in-a-matrix 23ece9e47b area of tri rec and circ 2021-06-14 22:49:46 -04:00
array-in-a-matrix 761c706a29 makefile added 2021-06-14 22:19:14 -04:00
superdimensional e4b2b15243 changed ints to doubles [needs review] 2021-04-27 03:18:35 -04:00
array-in-a-matrix ff218e15c8
Merge pull request #3 from array-in-a-matrix/beta
Beta
2021-04-19 16:39:00 -04:00
array-in-a-matrix 8db7e59bb9
Merge pull request #1 from array-in-a-matrix/beta
added text to readme
2021-04-19 15:52:52 -04:00
6 changed files with 69 additions and 19 deletions

2
.gitignore vendored
View file

@ -51,5 +51,5 @@ Module.symvers
Mkfile.old
dkms.conf
# random shit I test
# random shit
test.c

View file

@ -13,7 +13,10 @@ My goal for this project is to write an open sourced mathmatical library for C a
## List of calculators
- Hypotenuse calculator (a²+b²=c²)
- Circumference of a Circle
- Area of a circle (πr²)
- Area of a Triangle
- Area of a Rectangle
- Matrix arithmetics (2-D arrays)
- Determinant of 2*2 matrix
- Scalar multiplication
@ -27,12 +30,3 @@ My goal for this project is to write an open sourced mathmatical library for C a
- Matrix multiplication
- Determinant of n*n matrix
- Matrix support for none integer numbers
- Derivative
- Integral
- Area
- Area of a triangle
- Area of a quadralateral
- Peremeter
- Peremeter of a triangle
- Peremeter of a quadralateral
- Circumference of a circle

View file

@ -29,4 +29,19 @@ double areaOfCircle(double radius)
area = acos(-1) * pow(radius, 2);
return area;
}
};
double areaOfTriangle(double height, double base)
{
return (height * base)*(1.0/2.0);
};
double areaOfRectangle(double height, double base)
{
return (height * base);
};
double circumferenceOfCircle(double radius)
{
return (2 * acos(-1) * radius);
};

47
main.c
View file

@ -18,6 +18,9 @@ int main()
printf("\n 6. * Matrix multiplication *");
printf("\n 7. Scalar matrix multiplication");
printf("\n 8. Exponent");
printf("\n 9. Area of Triangle");
printf("\n 10. Area of Rectangle");
printf("\n 11. Circumference of Circle");
printf("\n\n * Stared entries are not fully programmed.");
printf("\n Enter your choice here:_____");
@ -118,13 +121,13 @@ int main()
int numRows;
int numColumns;
int scalar;
double scalar;
printf("\nPlease enter the number of rows: ");
scanf("%d", &numRows);
printf("\nPlease enter the number of columns: ");
scanf("%d", &numColumns);
printf("\nPlease enter the scalar multiplier: ");
scanf("%d", &scalar);
scanf("%lf", &scalar);
scalarMultiplication(numRows, numColumns, scalar);
@ -133,8 +136,7 @@ int main()
system("clear");
printf("\n ~~ Exponenet ~~\n\n");
double base;
double exp;
double base, exp;
printf("\nPlease enter the base: ");
scanf("%lf", &base);
printf("\nPlease enter the exponent: ");
@ -143,6 +145,43 @@ int main()
printf("%lf to the power of %lf is equal to %lf.\n", base, exp, num);
break;
case 9:
system("clear");
printf("\n ~~ Area of Triangle ~~\n\n");
double triBase, triHeight;
printf("\nPlease enter the base: ");
scanf("%lf", &triBase);
printf("\nPlease enter the height: ");
scanf("%lf", &triHeight);
double triArea = areaOfTriangle(triHeight, triBase);
printf("The area of triangle is %lf.\n", triArea);
break;
case 10:
system("clear");
printf("\n ~~ Area of Rectangle ~~\n\n");
double recBase, recHeight;
printf("\nPlease enter the base: ");
scanf("%lf", &recBase);
printf("\nPlease enter the height: ");
scanf("%lf", &recHeight);
double recArea = areaOfRectangle(recHeight, recBase);
printf("The area of rectangle is %lf.\n", recArea);
break;
case 11:
system("clear");
printf("\n ~~ Circumference of a Circle ~~\n\n");
double cirRadius;
printf("\nPlease enter the radius: ");
scanf("%lf", &cirRadius);
double circumference = circumferenceOfCircle(cirRadius);
printf("The circumference is %lf.\n", circumference);
break;
default:
printf("\n Incorrect input, try again.\n");

2
makefile Normal file
View file

@ -0,0 +1,2 @@
all:
gcc main.c -lm -o "cli-calc.o"

View file

@ -57,9 +57,9 @@ int matrixAddition(int numRows, int numColumns)
return 0;
}
int scalarMultiplication(int numRows, int numColumns, int scalar)
int scalarMultiplication(int numRows, int numColumns, double scalar)
{
int matrix[numRows][numColumns];
double matrix[numRows][numColumns];
printf("\nEnter elements in matrix of size %d*%d! \n", numRows, numColumns);
@ -67,7 +67,7 @@ int scalarMultiplication(int numRows, int numColumns, int scalar)
{
for (int j = 0; j < numColumns; j++)
{
scanf("%d", &matrix[i][j]);
scanf("%lf", &matrix[i][j]);
}
}
@ -76,7 +76,7 @@ int scalarMultiplication(int numRows, int numColumns, int scalar)
{
for (int j = 0; j < numColumns; j++)
{
printf(" %d ", matrix[i][j] * scalar);
printf(" %lf ", matrix[i][j] * scalar);
}
printf("\n");
}