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 = ");
scanf("%d", &colA);
//read in size from user MATRIX B
printf("Enter in matriz B....\n");
printf("\t#row = ");
scanf("%d", &rowB);
printf("\t#col = ");
scanf("%d", &colB);
for (i = 0; i < rowA; i++)
{
for (j = 0; j
< colA; j++) {
printf("A[%d][%d] =", i + 1, j + 1);
scanf("%d", &A[i][j]);
}
}
for (i = 0; i < rowA; i++)
{
for (j = 0; j
< colA; j++) {
printf("%d ", A[i][j]);
}
printf("\n");
}
for (i = 0; i < rowB; i++)
{
for (j = 0; j
< colA; j++) {
printf("B[%d][%d] =", i + 1, j + 1);
scanf("%d", &B[i][j]);
}
}
for (i = 0; i < rowB; i++)
{
for (j = 0; j
< colB; j++) {
printf("%d ", B[i][j]);
}
printf("\n");
}
printf("Enter your calculation of
addition or subtraction Matrix A and B: ");
gets(str1);
printf("\n");
if (strcmp(str1,"a+b") == 0)
{
//ADDING A+B
if (rowA == rowB && colA ==
colB) {
for (i = 0; i
< rowA; i++) {
for (j = 0; j < colA; j++) {
sum[i][j] = A[i][j] +
B[i][j];
}
}
//printing
ADDING A+B
for (i = 0; i
< rowB; i++) {
for (j = 0; j < colB; j++) {
printf("%d ", sum[i][j]);
}
printf("\n");
}
}
else {
printf("Error!
Martix A and Matrix B MUST be teh same size!\n");
}
}
/*else if ((calCommand == 'a-b') ||
(calCommand == 'A-B')) {
//subtracting
A-B
if (rowA == rowB
&& colA == colB) {
for (i = 0; i < rowA; i++) {
for (j = 0; j < colA; j++)
{
sum[i][j]
= A[i][j] - B[i][j];
}
}
//printing ADDING A+B
for (i = 0; i < rowB; i++) {
for (j = 0; j < colB; j++)
{
printf("%d
", sum[i][j]);
}
printf("\n");
}
}
else {
printf("Error! Martix A and Matrix B MUST be teh
same size!\n");
}
}*/
return 0;
}
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#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 = ");
scanf("%d", &colA);
//read in size from user MATRIX B
printf("Enter in matriz B....\n");
printf("\t#row = ");
scanf("%d", &rowB);
printf("\t#col = ");
scanf("%d", &colB);
for (i = 0; i < rowA; i++) {
for (j = 0; j < colA; j++) {
printf("A[%d][%d] =", i + 1, j + 1);
scanf("%d", &A[i][j]);
}
}
for (i = 0; i < rowA; i++) {
for (j = 0; j < colA; j++) {
printf("%d ", A[i][j]);
}
printf("\n");
}
for (i = 0; i < rowB; i++) {
for (j = 0; j < colA; j++) {
printf("B[%d][%d] =", i + 1, j + 1);
scanf("%d", &B[i][j]);
}
}
for (i = 0; i < rowB; i++) {
for (j = 0; j < colB; j++) {
printf("%d ", B[i][j]);
}
printf("\n");
}
getchar();
printf("Enter your calculation of addition or subtraction Matrix A
and B: ");
gets(str1);
printf("\n");
if (strcmp(str1,"a+b") == 0) {
//ADDING A+B
if (rowA == rowB && colA == colB) {
for (i = 0; i < rowA; i++) {
for (j = 0; j < colA; j++) {
sum[i][j] = A[i][j] + B[i][j];
}
}
//printing ADDING A+B
for (i = 0; i < rowB; i++) {
for (j = 0; j < colB; j++) {
printf("%d ", sum[i][j]);
}
printf("\n");
}
}
else {
printf("Error! Martix A and Matrix B MUST be teh same
size!\n");
}
}
/*else if ((calCommand == 'a-b') || (calCommand == 'A-B')) {
//subtracting A-B
if (rowA == rowB && colA == colB) {
for (i = 0; i < rowA; i++) {
for (j = 0; j < colA; j++) {
sum[i][j] = A[i][j] - B[i][j];
}
}
//printing ADDING A+B
for (i = 0; i < rowB; i++) {
for (j = 0; j < colB; j++) {
printf("%d ", sum[i][j]);
}
printf("\n");
}
}
else {
printf("Error! Martix A and Matrix B MUST be teh same
size!\n");
}
}*/
return 0;
}

Kindly revert for any queries
Thanks.
I am trying to add a string command to my code. what am i doing wrong?...
****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: ");...
I am trying to figure out why my C code is outputting "exited, segmentation fault". The game is supposed to generate 4 random numbers and store them in the "secret" array. Then the user is suppose to guess the secret code. The program also calculates the score of the user's guess. For now, I printed out the random secret code that has been generated, but when the game continues, it will output "exited, segmentation fault". Also, the GetSecretCode function has...
Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct { char name[MAX_SIZE1]; int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...
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...
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...
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 = ...
Can someone tell me why this is not printing in the screen. I know i commented out the first couple functions but the last one is not working. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <time.h> #define ROWS 5 #define COLS 5 #define FREE 2 #define SCALE 15 #define SHIFT 1 #define MAXVAL 75 #define FALSE 0 #define TRUE 1 void welcomeScreen(); void clearScreen(); void displayExplicitCard(); void displayCard(); void displayRandomCard(); void fillCardRand(); void setValue(); void displayBingoCard(); void initializeArrays (); int main...
So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...
Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions: 1. First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....
Can someone explain this code with comments I am supposed to dispay an array an add each columns and add each row An application uses a two-dimensional array declared as follows: int[][] days = new int[29][5]; a. Write code that sums each row in the array and displays the results. b. Write code that sums each column in the array and displays the results. class TwoDimensionalArrayDemo { public static void main( String[] arg ) { int[][] days = new int[29][5];...