****C PROGRAMMING****
Why isn't the determinant part of my code not running? I have included the attachments below and would greatly appreciate some help.
---------------------------------------
case 6:
printf("You chose determinate!\n\n");
printf("Press 2 for 2x2\n OR \n Press 3 for 3x3
Matrix: ");
scanf("%d", &detChoice);
printf("\n");
if (detChoice == 2) {
printf("Matrix: ");
scanf("%d",
&detChoice);
printf("Enter elements in
matrix of size 2x2: \n");
printf("\n\nEnter the 4
elements of the array\n");
for (i = 0; i < 2;
i++)
for (j =
0; j < 2; j++)
scanf("%d", &a[i][j]);
printf("\n\nThe entered
matrix is: \n\n");
for (i = 0; i < 2;
i++)
{
for (j =
0; j < 2; j++)
{
printf("%d\t", a[i][j]); // to print the
complete row
}
printf("\n"); // to move to the next row
}
// finding the determinant of
a 2x2 matrix
determinant = a[0][0] *
a[1][1] - a[1][0] * a[0][1];
printf("\n\nDterminant of 2x2
matrix is : %d\n", a[0][0] * a[1][1], a[1][0] * a[0][1],
determinant);
}
else if (detChoice == 3) {
printf("Matrix: ");
scanf("%d",
&detChoice);
printf("Enter elements in
matrix of size 3x3: \n");
printf("\n\nEnter the 9
elements of the array\n");
for (i = 0; i < 3;
i++)
for (j =
0; j < 3; j++)
scanf("%d", &a[i][j]);
printf("\n\nThe entered
matrix is: \n\n");
for (i = 0; i < 3;
i++)
{
for (j =
0; j < 3; j++)
{
printf("%d\t", a[i][j]); // to print the
complete row
}
printf("\n"); // to move to the next row
}
// finding the determinant of
a 3x3 matrix
determinate = a[0][0] *
((a[1][1] * a[2][2]) - (a[2][1] * a[1][2])) - a[0][1] *
(a[1][0]
* a[2][2]
- a[2][0] * a[1][2]) + a[0][2] * (a[1][0] * a[2][1] - a[2][0] *
a[1][1]);
printf("\nDeterminant of 3X3
matrix: %d", determinate);
}
else
printf("ERROR! Determinant is
only available on a 2 by 2 or 3 by 3 Matricies.\n\n");
break;
------------------------------
I need it for both 2 by 2 and 3 by 3 matricies depending on what the user is asking for. Thank you so much!
There were certain changes that i did in the formula and also there were to extra scanf which were used out of not use. I am pasting the code that i made and after that i am pasting the code of your's with correction.
Code:
#include <stdio.h>
int main()
{
int detChoice,i,j,determinant ;
printf("You chose determinate!\n\n");
printf("Press 2 for 2x2\n OR \nPress 3 for 3x3 Matrix: \n");
scanf("%d", &detChoice);
printf("\n");
if (detChoice == 2) {
printf("Matrix: ");
//scanf("%d", &detChoice);
int a[2][2];
printf("Enter elements in matrix of size 2x2: \n");
printf("\n\nEnter the 4 elements of the array\n");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
scanf("%d", &a[i][j]);
printf("\n\nThe entered matrix is: \n\n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
printf("%d\t", a[i][j]); // to print the complete row
}
printf("\n"); // to move to the next row
}
// finding the determinant of a 2x2 matrix
determinant = ((a[0][0] * a[1][1]) - (a[1][0] * a[0][1]));
printf("\n\nDterminant of 2x2 matrix is : %d\n", determinant);
}
else if (detChoice == 3) {
printf("Matrix: ");
int a[3][3];
printf("Enter elements in matrix of size 3x3: \n");
printf("\n\nEnter the 9 elements of the array\n");
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
scanf("%d", &a[i][j]);
printf("\n\nThe entered matrix is: \n\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d\t", a[i][j]); // to print the complete row
}
printf("\n"); // to move to the next row
}
// finding the determinant of a 3x3 matrix
determinant = (a[0][0] * (a[1][1] * a[2][2] - a[2][1] * a[1][2]))
-
(a[0][1] * (a[1][0] * a[2][2] - a[2][0] * a[1][2]))
+
(a[0][2] * (a[1][0] * a[2][1] - a[2][0] * a[1][1]));
printf("\nDeterminant of 3X3 matrix: %d", determinant );
}
else
printf("ERROR! Determinant is only available on a 2 by 2 or 3 by 3 Matricies.\n\n");
return 0;
}
Output:

Now below is the code you gave with corrections:
case 6:
printf("You chose determinate!\n\n");
printf("Press 2 for 2x2\n OR \nPress 3 for 3x3 Matrix: \n");
scanf("%d", &detChoice);
printf("\n");
if (detChoice == 2) {
printf("Matrix: ");
//scanf("%d", &detChoice);
int a[2][2];
printf("Enter elements in matrix of size 2x2: \n");
printf("\n\nEnter the 4 elements of the array\n");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
scanf("%d", &a[i][j]);
printf("\n\nThe entered matrix is: \n\n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
printf("%d\t", a[i][j]); // to print the complete row
}
printf("\n"); // to move to the next row
}
// finding the determinant of a 2x2 matrix
determinant = ((a[0][0] * a[1][1]) - (a[1][0] * a[0][1]));
printf("\n\nDterminant of 2x2 matrix is : %d\n", determinant);
}
else if (detChoice == 3) {
printf("Matrix: ");
int a[3][3];
printf("Enter elements in matrix of size 3x3: \n");
printf("\n\nEnter the 9 elements of the array\n");
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
scanf("%d", &a[i][j]);
printf("\n\nThe entered matrix is: \n\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d\t", a[i][j]); // to print the complete row
}
printf("\n"); // to move to the next row
}
// finding the determinant of a 3x3 matrix
determinant = (a[0][0] * (a[1][1] * a[2][2] - a[2][1] * a[1][2]))
-
(a[0][1] * (a[1][0] * a[2][2] - a[2][0] * a[1][2]))
+
(a[0][2] * (a[1][0] * a[2][1] - a[2][0] * a[1][1]));
printf("\nDeterminant of 3X3 matrix: %d", determinant );
}
else
printf("ERROR! Determinant is only available on a 2 by 2 or 3 by 3 Matricies.\n\n");
break;
Feel free to reach out to me in case of any doubt or clarification. I will be more than happy to reply.
You chose determinate! Press 2 for 2x2 OR Press 3 for 3x3 Matrix: Matrix: Enter elements in matrix of size 3x3: Enter the 9 elements of the array 10 20 30 17 13 21 19 29 31 The entered matrix is: 10 17 19 20 13 29 30 21 Determinant of 3x3 matrix: 2760 ... Program finished with exit code O Press ENTER to exit console.
****C PROGRAMMING**** Why isn't the determinant part of my code not running? I have included the...
Explain what the problem is within the program. Fix the problem when you create a child process per column. The code is given below. So basically, after the child processes have successfully excuted their code, the final print statement does not give the correct values. It prints the original matrix rather than the multiplied matrix.#include #include #include #include int main(int argc, char *argv[]){ int row = 0; int column = 0; row = atoi(argv[1]); column = atoi(argv[2]); int *A = ...
I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) { int i, j; int rowA, colA, rowB, colB; int A[10][10], B[10][10]; int sum[10][10]; char str1[10]; printf("This is a matrix calculator\n"); //read in size from user MATRIX A printf("Enter in matrix A....\n"); printf("\t#row = "); scanf("%d", &rowA); printf("\t#col = "); ...
C program-- the output is not right please help me to correct it. #include <stdio.h> int main() { int arr[100]; int i,j,n,p,value,temp; printf("Enter the number of elements in the array: \n "); scanf("%d",&n); printf("Enter %d elements in the array: \n",n); for(i=0;i<n;i++) { printf("\nelement %d: ",i); scanf("\n%d",&arr[i]); } printf("\nEnter the value to be inserted: \n "); scanf("\n%d",&value); printf("The exist array is: \n"); for(i=0;i<n;i++) { printf("%d",arr[i]); } p=i; for(i=0;i<n;i++) if(value<arr[i] ) { p = i; break; } arr[p]=value; printf("\n"); for (i =...
My homework is to write a tic tac toe function, this code isn't working and I can not find the error. It prints the board and accepts user input just fine, the only problem is the checkBoard function. I can not get it to return a value(player win) to end the while loop. #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int checkBoard(char board[3][3]) { int i, j; for (i = 0; i < 3; i += 1) { if...
I'm having trouble sorting this square matrix (a 2d array that has number of rows and same number of column n x n) using row-wise approach in C programming. Please help me program this in C to sort it using row-wise approach, here is the code: #include <stdio.h> #define MAX 100 int main() { int mat[MAX][MAX]; int i, j, m, n; int rowsum, columnsum, diagonalsum; int k; int magic = 0; int transpose[MAX][MAX]; printf("Enter the # of rows and columns...
#include "stdio.h" int main() { float array[5][3],rowsum=0.0,colsum=0.0; int i,j; for(i=0;i<5;i++){ printf("Enter the %d elements of array:\n",i); for(j=0;j<3;j++){ scanf("%f",&array[i][j]); } } printf("Given table data:\n"); for(i=0;i<5;i++){ for(j=0;j<3;j++){ printf(" %0.1f",array[i][j]); } printf("\n"); } for(i=0;i<5;i++){ for(j=0;j<3;j++){ rowsum=rowsum+array[i][j]; } printf("sum of the %d row is %0.1f\n",i,rowsum); rowsum=0; } for(j=0;j<3;j++){ colsum+=array[j][i]; printf("Sum of %d coloumn is %0.1f\n",j,colsum); colsum=0; } return(0); } can someone help me to get the correct row sum and column sum in c program
I need some with this program, please look at the changes I need closely. Its running correctly, but I need to do a few adjustments here is the list of changes I need: 1. All of the integers on a single line, sorted in ascending order. 2. The median value of the sorted array on a single line 3. The average of the sorted array on a single line Here is the program: #include<stdio.h> #include<stdlib.h> /* This places the Adds...
I'm having trouble correctly sorting my 2d array/matrix. I need it so its row-wise sorted (meaning the values in the rows go from low to high). I tried to make the sort function but it just puts all the numbers from lowest to highest, up to down in column format. So please please help me fix it so it sorts correctly, I have bolded the code that needs to be fixed, everything else is fine. The code is below: #include...
Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) { char size; double Matrix[size][size+1]; printf("Enter 9 elements of the matrix:\n"); int i; for (i = 0: i <= size: i++) { int j = 0; for (; j <= size++; j++){ scanf("%d", matrix[i--][4]) } } Display(Matrix,9); return 0; void...
This should be done in C. I have the code written to where it gives me the output however it is out of order from where it should be. The input should be 5 3 -7 3 5 -7 3 the output should be -7 occurs 2 times 3 occurs 3 times 5 occurs 2 times. My issue is I believe I need a bubble sort before my last loop but am unsure how to do it. #include <stdio.h> int...