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:

Write a program in JAVA To find the sum of any number of integers entered as command line arguments

Write a program in JAVA To find the sum of any number of integers entered as command line arguments

Share:

Write a program in JAVA to find GCD of two number

    


Write a program in JAVA to find gcd of two number

import java.util.Scanner;

class GCD {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.print("Enter First Number : ");
int num1=sc.nextInt();
System.out.print("Enter Second Number : ");
int num2=sc.nextInt();
sc.close();
while (num1!=num2) {
if (num1>num2) {
num1=num1-num2;
} else {
num2=num2-num1;
}
}
System.out.print("GCD = "+num1);
}
}

OUTPUT

Enter First Number : 24
Enter Second Number : 78
GCD : 6
Share:

Write a program in Java to find and print all the roots of quadratic equation

  


Write a program in JAVA to find and print all the roots of quadratic equation

import java.util.Scanner;

public class QuadEq {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a, b, c, val1, val2;
System.out.print("Enter The value of a in ax^2+bx+c : ");
a = sc.nextDouble();
System.out.print("Enter The value of b in ax^2+bx+c : ");
b = sc.nextDouble();
System.out.print("Enter The value of c in ax^2+bx+c : ");
c = sc.nextDouble();
sc.close();
double dis = Math.pow(b, 2) - 4 * a * c;
if (dis == 0) {
val1 = (-b) / (2 * a);
System.out.print("Roots are Real & Equal. X1 = x2 = : " + val1);
} else if (dis > 0) {
val1 = (-b + Math.sqrt(dis)) / (2 * a);
val2 = (-b - Math.sqrt(dis)) / (2 * a);
System.out.print("Roots are Real & Different. X1 = : " + val1 + " & X2 = " + val2);
} else {
val1 = -b / (2 * a);
val2 = (Math.sqrt(-dis)) / (2 * a);
System.out.println("Roots are Complex & Different.");
System.out.println("X1 = " + val1 + " + " + val2 + "i" + "\nX2 = " + val1 + " - " + val2 + "i");
}

}
}

OUTPUT

Enter The value of a in ax^2+bx+c : 1
Enter The value of b in ax^2+bx+c : -4
Enter The value of c in ax^2+bx+c : 6.25
Roots are Complex & Different.
X1 = 2.0 + 1.5i
X2 = 2.0 - 1.5i
Share:

Write a program in java to reverse the digit of given number

   


Write a program in JAVA to Reverse the digit of given number

import java.io.*;
public class RevNum {
public static void main(String[] args)throws IOException {
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Number");
int num = Integer.parseInt(obj.readLine());
int rem,rnum=0;
while (num!=0) {
rem=num%10;
rnum=rnum*10+rem;
num=num/10;
}
System.out.println("Reversed number is :"+rnum);
}
}

OUTPUT

Enter Number
12345
Reversed number is :54321
Share:

Write a program in Java to input and print 3x3 Matrix

  


Write a program in JAVA to input and print 3X3 Matrix

import java.io.*;

public class Matrix {
public static void main(String[] args) throws IOException {
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter elements of 3X3 matrix : ");
int arr[][] = new int[3][3];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
arr[i][j] = Integer.parseInt(obj.readLine());
}
}
System.out.println("Entered 3x3 Matrix is : ");
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}

OUTPUT

Enter elements of 3X3 matrix : 12
34
56
23
45
67
11
32
87

Entered 3x3 Matrix is :
12 34 56
23 45 67
11 32 87


Share:

Write a program in java to print sum of two 3X3 matrix

  


Write a program in JAVA to print sum of two 3X3 MATRIX

import java.io.*;

class SumMatrix3D {
public static void main(String[] args)throws IOException {
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter elements of first 3X3 matrix : ");
int arr1[][]=new int[3][3];
for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr1.length; j++) {
arr1[i][j]=Integer.parseInt(obj.readLine());
}
}
System.out.print("Enter elements of second 3X3 matrix : ");
int arr2[][]=new int[3][3];
for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr1.length; j++) {
arr2[i][j]=Integer.parseInt(obj.readLine());
}
}
int sum[][]=new int[3][3];
for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr1.length; j++) {
sum[i][j]=arr1[i][j]+arr2[i][j];
}
}
System.out.println("Sum Of both Matrix : ");
for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr1.length; j++) {
System.out.print(sum[i][j]+" ");
}
System.out.println();
}
}
}

OUTPUT

Enter elements of first 3X3 matrix : 1
2
3
4
5
6
7
8
9
Enter elements of second 3X3 matrix : 9
2
3
4
5
1
6
7
8
Sum Of both Matrix : 
10 4 6 
8 10 7 
13 15 17 
Share:

Write a program in JAVA to input a number and check if it is armstrong or not

   

Write a program  in JAVA to input a number and check if it is  armstrong or not

Armstrong Number : Armstrong number is a number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers

import java.io.*;
public class Armstrong {
public static void main(String[] args)throws IOException {
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a Positive Number : ");
int num=Integer.parseInt(obj.readLine());
int ldigit,cube=0;
int temp=num;
while (temp!=0) {
ldigit=temp%10;
cube+=ldigit*ldigit*ldigit;
temp=temp/10;
}
if (cube == num) {
System.out.println(num+" Is Armstrong Number");
} else {
System.out.println(num+" Is Not an Armstrong Number");
}
}
}


OUTPUT

1. 
     Enter A Number : 371
     371 is armstrong number 

2. 
     Enter A Number : 476
     476 is not a armstrong number



Share:

Write a Java program to input a number and check if it is prime or not

 

Write a program  in Java to input a number and check if it is  prime or not

Prime Number : A number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11).

import java.util.Scanner;
public class Prime {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter A Positive Number : ");
int num=sc.nextInt();
sc.close();
boolean isPrime=true;
if (num==1) {
System.out.print(" 1 Is Unitary");
} else if(num==2) {
System.out.print(" 2 Is Prime Number");
}else {
for (int i = 2; i < num/2; i++) {
if (num%i==0) {
isPrime=false;
break;
}
}
if (isPrime) {
System.out.print(num +" Is Prime Number");
} else {
System.out.print(num +" Is Not Prime Number");
}
}
}
}

OUTPUT

1.
   Enter A Positive Number : 45
   45 Is Not Prime Number

2.
   Enter A Positive Number : 47
   47 Is Prime Number

Program 2

Share:

Write a Java program to input a number and check if it is palindrome or not

 Write a program  in Java to input a number and check if it is  palindrome or not

Palindrome : palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.

import java.util.Scanner;

public class Palin {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.print("Enter A Number : ");
int num =sc.nextInt();
int rev=0,ldigit;
int temp=num;
while (temp!=0) {
ldigit=temp%10;
rev=rev*10+ldigit;
temp=temp/10;
}
if (num==rev) {
System.out.println(num +" is Palindrome");
} else {
System.out.println(num +" is not Palindrome");
}
}
}


 

OUTPUT

1. 
     Enter a Number : 123454321
     123454321 is Palindrome

2. 
     Enter a Number : 345232
     345232 is not Palindrome



Share:

Write a program in c++ to check if entered 3x3 matrix is a diagonal matrix

 


Write a program in c++ to check if entered 3x3 matrix is a diagonal matrix


#include <iostream>
using namespace std;
int main()
{
    int a[3][3], flag = 0;
//Loop to enter elements of matrix    
    cout << "Enter Elements of Array : ";
    for (int i = 0i < 3i++)
    {
        for (int j = 0j < 3j++)
        {
            cin >> a[i][j];
        }
    }
// Loop to print matrix    
    cout<<"Entered Matrix : "
    for (int i = 0i < 3i++)
    {
        cout << endl;
        for (int j = 0j < 3j++)
        {
            cout << a[i][j<< " ";
        }
    }
//Loop to check for diagonal matix    
    for (int i = 0i < 3i++)
    {
        for (int j = 0j < 3j++)
        {
            if (i == j && a[i][j] == 0)
            {
                flag = 1;
                break;
            }
            else if (i != j && a[i][j] != 0)
            {
                flag = 1;
                break;
            }
        }
    }
    if (flag == 1)
    {
        cout << "\n This is not a Diagonal Matrix ";
    }
    else
        cout << "\n This is  Diagonal Matrix ";

    return 0;
}

OUTPUT

Enter Elements of Array : 12
34
23
56
45
11
67
76
54
Entered Matrix : 
12 34 23
56 45 11
67 76 54
This is not a Diagonal Matrix
Share:

Write a program in c++ to input and print 3X3 Matrix

 


Write a program in c++ to input and print 3X3 Matrix

#include <iostream>
using namespace std;
int main()
{
    int a[3][3];
    cout << "Enter Elements of Array : ";
//Loo-p to Enter Elements    
    for (int i = 0i < 3i++)
    {
        for (int j = 0j < 3j++)
        {
            cin >> a[i][j];
        }
    }
// Loop to print Matrix    
    cout<<"3x3 Matrix :"<<endl;
    for (int i = 0i < 3i++)
    {
        cout << endl;
        for (int j = 0j < 3j++)
        {
            cout << a[i][j<< " ";
        }
    }
    return 0;
}

OUTPUT

Enter Elements of Array : 12
34
56
23
45
67
11
32
87

3x3 Matrix :
12 34 56
23 45 67
11 32 87


Share:

Write a program in c++ to input 5 number and find the largest

   

Write a program in c++ to input 5 number and find the largest


#include <iostream>
using namespace std;
int main()
{
    int i;
    float a[5], sum = 0;
    cout << "Enter 5 Number : " << endl;
    for (i = 0i < 5i++)
    {
        cout << i+1 << ". ";
        cin >> a[i];
    }
    for (i = 0i < 5i++)
    {
        if (a[0]<a[i])
     
           a[0]=a[i] ;
      
    }

    cout << "\n largest number = " <<a[0];
    return 0;
}

OUTPUT

Enter 10 Number : 
1. 23
2. 56
3. 102
4. 78.4
5. 34.67

largest number = 102













Share:

Write a program in c++ to input 5 number and find the sum

  

Write a program in c++ to input 5 number and find the sum


#include <iostream>
using namespace std;
int main()
{  float a[5], sum = 0;
    int i;
    cout << "Enter 5 Number : " << endl;
    for (i = 0i < 5i++)
    {
        cout << i+1 << ". ";
        cin >> a[i];
        sum+=a[i];
    }
    
   
    cout << "\n sum = " << sum;
    return 0;
}

OUTPUT

Enter 5 Number : 
1. 23
2. 56
3. 102
4. 78.4
5. 34.67

 sum = 294.07













Share:

Write a program in c++ to input a number and check if it is prime or not

    

Write a program  in c++ to input a number and check if it is  prime or not

Prime Number : A number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11).

#include <iostream>
using namespace std;

int main()
{
    int numprime = 0;
    cout << "\t PROGRAM TO CHECK PRIME NUMBER";
    cout << "\n Enter A Number : ";
    cin >> num;
    if (num < 1)
        cout << "\n Number should be greater than 0";
    else if (num == 1)
        cout << "\n 1 is neither Prime nor Composite, It is a Neutral Number";
    else
    {

        for (int i = 2i <= num / 2; ++i)
        {
            if (num % i == 0)
            {
                prime = 1;
                cout << " It is not a Prime Number";
                break;
            }
        }

        if (prime == 0)
            cout << " It is a Prime Number";
        return 0;
    }
}


OUTPUT

1. 
        PROGRAM TO CHECK PRIME NUMBER
   Enter A Number : 45
   It is not a Prime Number

2. 
     PROGRAM TO CHECK PRIME NUMBER
   Enter A Number : 47
   It is a Prime Number


Share:

Write a program in c++ to input a number and print reverse of this number

   

Write a program  in c++ to input a number and PRINT REVERSE OF THIS NUMBER


#include <iostream>
using namespace std;
int main()
{
    int numrevldigit;
    cout << "Enter a Number : ";
    cin >> num;
    while (num != 0)
    {
        ldigit = num % 10;
        rev = rev * 10 + ldigit;
        num /= 10;
    }
    cout << "Reversed number is :" << rev;
   
}


OUTPUT

1. 
     Enter a Number : 23465
     Reversed number is :56432

2. 
     Enter a Number : 78654
     Reversed number is :45687



Share:

Write a program in c++ to input a number and check if it is palindrome or not

   

Write a program  in c++ to input a number and check if it is  palindrome or not

Palindrome : palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.

#include <iostream>
using namespace std;
int main()
{
    int nnumldigitrev = 0;
    cout << "Enter a Number : ";
    cin >> n;
    num = n;
    while (num != 0)
    {
        ldigit = num % 10;
        rev = rev * 10 + ldigit;
        num /= 10;
    }
    if (rev == n)
    {
        cout << n << " is palindrome";
    }
    else
        cout << n << " is not palindrome";
}

OUTPUT

1. 
     Enter a Number : 123454321
     123454321 is palindrome

2. 
     Enter a Number : 345232
     345232 is not palindrome



Share:

Pageviews

Blog Archive