Write a program in c++ to input and print the multiplication of two matrix

Write a program in c++ to input and print the multiplication of two matrix




#include <iostream>
using namespace std;
int main(){
    int r1,r2,c1,c2;
    cout<<"Enter Rows of First Matrix : ";
    cin>>r1;
    cout<<"Enter Columns of First Matrix : ";
    cin>>c1;
    cout<<"Enter Rows of Second Matrix : ";
    cin>>r2;
    cout<<"Enter Columns of Second Matrix : ";
    cin>>c2;
    int a[r1][c1],b[r2][c2],c[r1][c2];
    if (c1==r2)
    { //taking elements of first matrix
        cout<<"Enter Elements Of first Matrix "<<endl;
       for (int i = 0; i < r1; i++)
        {
                for (int j = 0; j < c1; j++)
                {
                    cin>>a[i][j];               
                }
        }
        //printing first matrix 
        cout<<"Elements Of first Matrix are "<<endl;
        for (int i = 0; i < r1; i++)
         {
                for (int j = 0; j < c1; j++)
                 {
                    cout<<a[i][j]<<" ";               
                 }
               cout<<endl;
        }
        //taking elements of second matrix
        cout<<"Enter Elements Of second Matrix "<<endl;
       for (int i = 0; i < r2; i++)
        {
                for (int j = 0; j < c2; j++)
                {
                    cin>>b[i][j];               
                }
        }
        //printing second matrix
        cout<<"Elements Of second Matrix are "<<endl;
        for (int i = 0; i < r2; i++)
         {
                for (int j = 0; j < c2; j++)
                 {
                    cout<<b[i][j]<<" ";               
                 }
               cout<<endl;
        }
        //multiplying first and second matrix
        for (int i = 0; i < r1; i++) 
        {
                for (int j = 0; j < c2; j++) 
                {
                    c[i][j] = 0;
                    for (int k = 0; k < r2; k++) 
                    {
                        c[i][j] = c[i][j] + a[i][k] * b[k][j];
                    }
                }
        }
        //printing multiplied matrix
            cout<<"Matrix after multiplication "<<endl;
             for (int i = 0; i < r1; i++)
              {
                for (int j = 0; j < c2; j++)
                 {
                    cout<<" " << c[i][j] << " ";
                }
                cout<<endl;
             }

        
    } else 
        {
            cout<<"Sorry!! can't Multiply";
        }
    
}





Share:

Write a program in java to input 10 numbers and find smallest among them

Write a program in java to input 10 numbers and find smallest among them



import java.util.*;
public class ArrSmaller {
    public static void main(String[] args) {
        Scanner obj = new Scanner(System.in);
        System.out.println("Enter 10 Number : ");
        int arr[]= new int[10];
        int check;
        for (int i = 0; i < 10; i++) {           
        arr[i]=obj.nextInt();
      }
         check=arr[0];
         obj.close();
         for (int i = 0; i < 10; i++) {
             if (arr[i]<check) {
                 check = arr[i];                
             }

         }
      System.out.println("Smallest Number : "+ check);
    }
    
}


Share:

Write a program in java to input 10 numbers and find largest among them

Write a program in java to input 10 numbers and find largest among them



import java.io.*;
public class ArrLarger {
    public static void main(String[] args)throws IOException {
        BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter 10 Numbers : ");
        int arr[] = new int[10];
        int check = 0;
        int i;
        for (i = 0; i < 10; i++) {
            arr[i]=Integer.parseInt(obj.readLine());          
        }
     for (i = 0; i < 10; i++) {
         if (arr[i]>check) {
             check =arr[i];
         }         
     }
     System.out.println("Largest Number Is : "+ check);
    } 
}


Share:

Write a program in java to input and print the multiplication of two matrix

Write a program in java to input and print the multiplication of two matrix

Share:

Write a program to show that during function overloading, if no matching argument is found, then java will apply automatic type conversions(from lower to higher data type)

Write a program to show that during function overloading, if no matching argument is found, then java will apply automatic type conversions(from lower to higher data type)

Share:

Write a program in JAVA To find the factorial of a given number

Write a program in JAVA To find the factorial of a given number

Share:

Write a program to create your own exception types to handle situation specific to your application (Hint: Define a subclass of Exception which itself is a subclass of Throwable).

Write a program to create your own exception types to handle situation specific to your application (Hint: Define a subclass of Exception which itself is a subclass of Throwable).

Share:

Write a program to show the use of nested try statements that emphasizes the sequence of checking for catch handler statements.

Write a program to show the use of nested try statements that emphasizes the sequence of checking for catch handler statements.

Share:

Write a program “DivideByZero” that takes two numbers a and b as input, computes a/b, and invokes Arithmetic Exception to generate a message when the denominator is zero.

Write a program “DivideByZero” that takes two numbers a and b as input, computes a/b, and invokes Arithmetic Exception to generate a message when the denominator is zero.

Share:

Write a program that creates illustrates different levels of protection in classes/subclasses belonging to same package or different packages

Write a program that creates illustrates different levels of protection in classes/subclasses belonging to same package or different packages

Not executable here

Run this program in your device

Code of program1 in Package

Code of program2 in same Package

Code of program outside the package

Share:

Write a program to create a multilevel package and also creates a reusable class to generate Fibonacci series, where the function to generate fibonacii series is given in a different file belonging to the same package.

Write a program to create a multilevel package and also creates a reusable class to generate Fibonacci series, where the function to generate fibonacii series is given in a different file belonging to the same package.

Not executable here

Run this program in your device

Code of Package

Make a Folder of any name eg. Fibpackage

Under that folder put code of package with any name eg.Fibpackage.java

Code to import Package

import the code of package file you put in your folder

in my case folder is MultiFile and name of code file is Fibpackage.java so import Fibpackage.Fibpackage.java

Share:

Create a multi-file program where in one file a string message is taken as input from the user and the function to display the message on the screen is given in another file (make use of Scanner package in this program)

Create a multi-file program where in one file a string message is taken as input from the user and the function to display the message on the screen is given in another file (make use of Scanner package in this program)

Not executable here

Run this program in your device

Code of Package

Make a Folder of any name eg. MultiFile

Under that folder put code of package with any name eg.MultiFilepackage.java

Code to import Package

import the code of package file you put in your folder

in my case folder is MultiFile and name of code file is MultiFilepackage.java so import MultiFile.MultiFilepackage.java

Share:

Write a program to demonstrate the concept of boxing and unboxing.

Write a program to demonstrate the concept of boxing and unboxing.

Share:

Write a program to show the use of static functions and to pass variable length arguments in a function

Write a program to show the use of static functions and to pass variable length arguments in a function

Share:

Write a program to show the difference between public and private access specifiers. The program should also show that primitive data types are passed by value and objects are passed by reference and to learn use of final keyword

Write a program to show the difference between public and private access specifiers. The program should also show that primitive data types are passed by value and objects are passed by reference and to learn use of final keyword

Share:

Write a program to Modify the ―distance class by creating constructor for assigning values (feet and inches) to the distance object. Create another object and assign second object as reference variable to another object reference variable. Further create a third object which is a clone of the first object

Write a program to Modify the ―distance class by creating constructor for assigning values (feet and inches) to the distance object. Create another object and assign second object as reference variable to another object reference variable. Further create a third object which is a clone of the first object

Share:

Write a program to create a ―distance class with methods where distance is computed in terms of feet and inches, how to create objects of a class and to see the use of this pointer

Write a program to create a ―distance class with methods where distance is computed in terms of feet and inches, how to create objects of a class and to see the use of this pointer

Share:

Write a program in java that show working of different functions of String and StringBufferclasss like setCharAt(, setLength(), append(), insert(), concat()and equals()

Write a program in java that show working of different functions of String and StringBufferclasss like setCharAt(, setLength(), append(), insert(), concat()and equals()

Share:

Write a program in java To find the sum of any number of integers interactively, i.e., entering every number from the keyboard, whereas the total number of integers is given as a command line argument

Write a program in java To find the sum of any number of integers interactively, i.e., entering every number from the keyboard, whereas the total number of integers is given as a command line argument

Share:

Write a program in java to check if a number is prime or not, by taking the number as input from the keyboard.

Write a program in java to check if a number is prime or not, by taking the number as input from the keyboard

Share:

Write a program in java to convert a decimal to binary number

Write a program in java to convert a decimal to binary number

Share:

To learn use of length in case of a two dimensional array.

To learn use of .lenth in case of a two dimensional array

Share:

To learn use of single dimensional array by defining the array dynamically.

To learn use of single dimensional array by defining the array dynamically

Share:

Pageviews