Question

In: Computer Science

In C programming language, write the program "3x3" in size, calculating the matrix "c = a...

In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?

Solutions

Expert Solution

C Program:

#include <stdio.h>
#include <stdlib.h>

#define RMAX 10
#define CMAX 10

int main()
{
    int i, j, k, r, c;

    int A[RMAX][CMAX], B[RMAX][CMAX], Z[RMAX][CMAX];

    printf("Enter #rows #columns: ");
    scanf("%d %d", &r, &c);

    //Reading matrix
    printf("\n Enter %d elements for matrix A: ", (r*c));

    //Iterating over rows
    for(i=0; i<r; i++)
    {
        //Iterating over columns
        for(j=0; j<c; j++)
        {
            scanf("%d", &A[i][j]);
        }
    }

    //Reading matrix
    printf("\n Enter %d elements for matrix B: ", (r*c));

    //Iterating over rows
    for(i=0; i<c; i++)
    {
        //Iterating over columns
        for(j=0; j<r; j++)
        {
            scanf("%d", &B[i][j]);
        }
    }

    //Matrix Multiplication
    for(i=0; i<r; i++)
    {
        //Iterating over columns
        for(j=0; j<r; j++)
        {
            //Set to zero
            Z[i][j] = 0;

            for(k=0; k<c; k++)
            {
                //Matrix Multiplication
                Z[i][j] += (A[i][k] * B[k][j]);
            }
        }
    }

    //Printing matrix Z
    printf("\n Matrix Z: \n\n");

    //Iterating over rows
    for(i=0; i<r; i++)
    {
        //Iterating over columns
        for(j=0; j<r; j++)
        {
            printf("%d\t", Z[i][j]);
        }
        printf("\n");
    }

    printf("\n");
    return 0;
}

Related Solutions

C Language - Programming Write a function that takes an array of ints, and the size...
C Language - Programming Write a function that takes an array of ints, and the size of the array – another int. It also returns a double. Call this one ‘average.’ Return a double that is the average of the values in the array. Demonstrate that it works by finding the average of an array with these values {78, 90, 56, 99, 88, 68, 92} Write a function that takes one double parameter, and returns a char. The parameter represents...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
In programming C language, write a program that creates a binary tree of words to be...
In programming C language, write a program that creates a binary tree of words to be used as a spell checking device for various text files. The list of words will come from a file “words.txt”. Your program is to read through the “words.txt” file and insert the word on that line into the tree in lexicographic order (also known as Dictionary order). Words in the file will be separated by spaces. Once this is done, your program should then...
In programming C language, write a program that creates a binary tree of words to be...
In programming C language, write a program that creates a binary tree of words to be used as a spell checking device for various text files. The list of words will come from a file “words.txt”. Your program is to read through the “words.txt” file and insert the word on that line into the tree in lexicographic order (also known as Dictionary order). Words in the file will be separated by spaces. Once this is done, your program should then...
Programming Language Required: C Write a multithreaded program in C (not c++) using the pthread library...
Programming Language Required: C Write a multithreaded program in C (not c++) using the pthread library and dynamic memory(malloc) that multiplies two matrices together. The numbers in the matrices must be read in from a text file. The program should also check if the two matrices are capable of being multiplied together. The amount of threads used has to be dynamic. The user should be able to choose how many threads they wish to use using the command line. Finally,...
C++ Program: Create a 3x3 matrix of int values. Implement five functions, each expecting the matrix...
C++ Program: Create a 3x3 matrix of int values. Implement five functions, each expecting the matrix as parameter input. The first function must use a nested loop to prompt a user to enter each value. Show the indices when prompting for input and populate the matrix with these values. The second function outputs the matrix and formats the output to align all columns and rows to accommodate values up to 1000. The third function finds and returns the minimum value...
C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
In C Programming Language Write a program to output to a text log file a new...
In C Programming Language Write a program to output to a text log file a new line starting with day time date followed by the message "SUCCESSFUL". Please screenshot the results.
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT