c. Write a program to add two matrices of same order MXN.
d. Write a program to find either given no is prime or not
e. Write a function to find simple interest
Answers
c)
import java.util.*;
public class Sum
{
public static void main(String args[])
{
Scanner in =new Scanner(System.in);
int M,X,N;
System.out.println("Enter the matrices of same order");
M= in.nextInt();
X=in.nextInt();
N=M+X;
System.out.println("The sum is="+N);
}
}
d)
import java.util.*;
public class Number
{
public static void main(String args[])
{
Scanner in =new Scanner(System.in[]);
int a,n;
System.out.println("Enter the number");
a=in.nextInt();
for(n=2;n<=a/2;a++)
{
if(a%n==0)
{
System.out.println("It is a composite number");
}
else
{
System.out.println("It is a prime number");
}
}
}
}
e)
import java.util.*;
public class SI
{
public static void main(String args[])
{
Scanner in= new Scanner(System.in);
int p;
float r,t;
double i;
System.out.println("Enter the rate of principal");
p=in.nextInt();
System.out.println("Enter the rate of interest");
r=in.nextFloat();
System.out.println("Enter the time");
t=in.nextFloat();
i=(p*r*t)/100;
System.out.println("The simple interest is="+i);
}
}
Explanation:
(c)
*In matrices the third order is the sum of the first two orders. In the question all the three orders are stated so sum of the first to orders might be the third order.
(d)
*Any number is divided by 1 and by that number so we should start dividing it by 2 to check whether it is prime or not. One number gets properly divisible upto its half range so we should divide upto its half range except dividing upto the whole range.
*If you wish you can divide upto the whole range but it doesn't create any change to the document it only makes he program lengthier.
(e)
*We should take the principal value in integer type as none keeps money in decimal value.
* The year and the rate of interest may can be in fraction so we should accept it into float data type.
* The interest may not be in whole number so we should accept it into double data type.
For more java programmings follow the given links as solved by me earlier_
brainly.in/question/14335606
brainly.in/question/14323927
brainly.in/question/14370842
brainly.in/question/14395545
brainly.in/question/14809512
brainly.in/question/14809885
https://brainly.in/question/14840551
C.
## This is really an interesting program.
## I used numpy for making this program work.
## You can install NumPy by going to the Command Prompt and then type pip install numpy
## Let's begin to code.
import numpy as np # Imported numpy as np
## Collected the number of rows and columns.
a = int(input("Enter the number of rows (between 1 and 100) : "))
b = int(input("Enter the number of columns (between 1 and 100) : "))
print("\nEnter elements of 1st matrix :\n")
# Creating an array for the first Matrix.
m = [[int(input("Enter value for {}. row and {}. column: ".format(r + 1, c + 1))) for c in range(a)] for r in range(b)]
print(np.array(m))
print("\nEnter elements of 2st matrix :\n")
# Creating an array for the second Matrix.
n = [[int(input("Enter value for {}. row and {}. column: ".format(r + 1, c + 1))) for c in range(a)] for r in range(b)]
print(np.array(n))
# Creating a blank array for the sum of the Matrix.
SUM = [[m[i][j] + n[i][j] for j in range(len(m[0]))] for i in range(len(m))]
# Printing the sum.
print("\nThe sum of the matrices are :\n")
print(np.array(SUM))
D.
## Allowing the user to input a number.
a = int(input("Enter any number to check whether it is a Prime Number : "))
# As 1 is not a prime number I gotta be using a Conditional statement.
if a > 1:
for i in range(2,a):
if (a%i)==0: # If the number provided by the user is divisible by any other number less than it.
print(a,"is not a Prime Number")
break
else:
print(a,"is a Prime Number")
else:
print(a,"is not a Prime Number")
E.
## Collecting the values for calculating the Simple Interest.
P=float(input("Enter the Pricipal amount : "))
R=float(input("Enter the Rate of interest : "))
T=float(input("Enter the number of years : "))
# Defining a Variable named SI with the formula.
SI=(P*R*T)/100
# Printing the Value.
print("Simple Interest is", SI)