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...
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.
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)...
Using the C Programming language, write a program that sums an array of 50 elements. Next,...
Using the C Programming language, write a program that sums an array of 50 elements. Next, optimize the code using loop unrolling. Loop unrolling is a program transformation that reduces the number of iterations for a loop by increasing the number of elements computed on each iteration. Generate a graph of performance improvement. Tip: Figure 5.17 in the textbook provides an example of a graph depicting performance improvements associated with loop unrolling. Marking:- Optimize the code for an array of...
In the C# programming language... Write a program to perform student record manage for class IST311....
In the C# programming language... Write a program to perform student record manage for class IST311. Create student record class (Student.cs) and it should get the student information from the user and set up student record class. The program will perform recording student’s grade information and compute final grade, and then print out the student’s class information. Student class definitions: It should contain attributes as following: first name, last name, 5 labs grade, 3 grade, final grade. Its member functions...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT