1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
IRINA_888 [86]
3 years ago
11

6. Write a program that can multiply an n x m matrix and m x n matrix together: The input specifications are these: Read n and m

using scanf function. Read two matrices using a for loop inside the main function. The output (product) matrix must be computed in a function named matrix_mult which will have the two input matrices as arguments.
Computers and Technology
1 answer:
Whitepunk [10]3 years ago
7 0

Answer:

see explaination

Explanation:

#include <stdio.h>

#include <malloc.h>

void matrix_mult(int **m1, int **m2, int **m3, int n, int m) {

int i, j, k, sum=0;

for(i = 0; i < n; ++i) {

for(j = 0; j < n; ++j) {

sum = 0;

for(k = 0; k < m; ++k) {

sum += m1[i][k] * m2[k][j];

}

m3[i][j] = sum;

}

}

}

int main() {

int n, m, i, j;

int **m1, **m2, **m3;

printf("Enter number of rows: ");

scanf("%d", &n);

printf("Enter number of columns: ");

scanf("%d", &m);

m1 = malloc(sizeof(int *) * n);

m2 = malloc(sizeof(int *) * m);

m3 = malloc(sizeof(int *) * n);

for(i = 0; i < m; ++i) {

m1[i] = malloc(sizeof(int) * m);

m2[i] = malloc(sizeof(int) * n);

m3[i] = malloc(sizeof(int) * n);

}

printf("Enter first matrix\n");

for(i = 0; i < n; ++i) {

for(j = 0; j < m; ++j) {

scanf("%d", &(m1[i][j]));

}

}

printf("Enter second matrix\n");

for(i = 0; i < m; ++i) {

for(j = 0; j < n; ++j) {

scanf("%d", &(m2[i][j]));

}

}

matrix_mult(m1, m2, m3, n, m);

printf("product is\n");

for(i = 0; i < n; ++i) {

for(j = 0; j < n; ++j) {

printf("%d ", m3[i][j]);

}

printf("\n");

}

printf("Enter first matrix: ");

return 0;

}

You might be interested in
A number of LC-3 instructions have an "evaluate address" step in the instruction cycle, in which a 16-bit address is constructed
hjlf

Answer: you want to list all LC structers

Explanation:

4 0
3 years ago
What does an arrow after a command indicate
Ainat [17]

Answer:

the command still has to be carried out.

3 0
2 years ago
Read 2 more answers
If String str = "Computer Science";, then what is the value of str.substring(10);? ​
Genrish500 [490]

Answer:

cience

Explanation:

From the question, the string variable str was initialized to "Computer Science:

str.substring(10) implies that we get a substring starting from the character at the 10th index till the last index

In this case, the 10th index character is c

So, the instruction will return cience

3 0
2 years ago
Write a loop that inputs words until the user enters STOP. After each input, the program should number each entry and print in t
vekshin1

I hope this helps you.

3 0
3 years ago
In an office there is a unisex bathroom with n toilets. The bathroom is open to both men and women, but it cannot be used by men
Gnesinka [82]

Answer:

Check the explanation

Explanation:

#include <stdio.h>

#include <stdlib.h>

#include <pthread.h>

#include <semaphore.h>

int mcount,wcount;

sem_t x,y,z,wsem,msem,cap;

void delay(void)

{

int i;

int delaytime;

delaytime = random();

for (i = 0; i<delaytime; i++);

}

void *woman(void *param)

{

sem_wait(&z);

sem_wait(&wsem);

sem_wait(&y);

wcount++;

if(wcount==1)

{ sem_wait(&msem); }

sem_post(&y);

sem_post(&wsem);

sem_post(&z);

sem_wait(&cap);

printf("woman in!\n");

delay();

printf("\twoman out!\n");

sem_post(&cap);  

sem_wait(&y);

wcount--;

if(wcount==0)

{ sem_post(&msem); }

sem_post(&y);

}

void *man(void *param)

{  

sem_wait(&z);

sem_wait(&msem);

sem_wait(&x);

mcount++;

if(mcount==1)

{ sem_wait(&wsem); }

sem_post(&x);

sem_post(&msem);

sem_post(&z);

sem_wait(&cap);

printf("\t\tman in!\n");

delay();

printf("\t\t\tman out!\n");

sem_post(&cap);

sem_wait(&x);

mcount--;

if(mcount==0)

{sem_post(&wsem);}

sem_post(&x);

}

int main(void)

{

int i;

srandom(60);

mcount = 0;

wcount = 0;

sem_init(&x,0,1); // for sem_init, initial value is 3rd argument

sem_init(&y,0,1);

sem_init(&z,0,1);

sem_init(&wsem,0,1);

sem_init(&msem,0,1);

sem_init(&cap,0,4); // eg. cap initialized to 4

pthread_t *tid;

tid = malloc(80*sizeof(pthread_t));

// You can use your cobegin statement here, instead of pthread_create()  

// I have forgone the use of pthread barriers although I suppose they would nicely imitate the functionality of cobegin.

// This is merely to retain simplicity.

for(i=0;i<10;i++)

{

pthread_create(&tid[i],NULL,woman,NULL);

}

for(i=10;i<20;i++)

{  

pthread_create(&tid[i],NULL,man,NULL);

}

for(i=0;i<20;i++)

{  

pthread_join(tid[i],NULL);

}

return(0);

}

5 0
3 years ago
Other questions:
  • 7. What is the school campus’s setting<br> the school is sanford
    6·2 answers
  • You are a network technician for a small corporate network. It's been decided that the office needs a wireless network for emplo
    6·1 answer
  • ___________ is an approach to boundary spanning that results from using sophisticated software to search through large amounts o
    8·1 answer
  • What does a page break do?
    13·1 answer
  • If a file you are opening for appending does not exist, the operating system will detect the missing file and terminate the oper
    14·1 answer
  • Which job role requires you to create user guides for computer products and services?
    11·1 answer
  • Examples of analog computer
    8·1 answer
  • Why do you think Jacinda believed what people told her about her own beauty? Even if you understand that what you see on social
    13·1 answer
  • What could happen if I break copyright law in the future​
    14·2 answers
  • Which directory contains the initrd file? in suse linux
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!