Question

In: Computer Science

Create a random matrix of size 10x10, of integers between 1 and 1000, and use nested...

Create a random matrix of size 10x10, of integers between 1 and 1000, and use nested for loops over the elements of the matrix to find the number of prime elements , as well as the sum of the prime elements in the matrix.

  • You can use MATLAB's built-in function isprime to check if an element is a prime number.
  • You should have these variable:
    • cnt (counts the number of prime elements)
    • sm (sum of prime elements)
  • In the command window print this sentence followed by a new line
There are ....  prime numbers and their sum is ...

Solutions

Expert Solution

MATLAB CODE:-

a=1;
b=1000;
cnt=0;
sm=0;
z = randi([1 1000],10,10)
for i=1:10
for j=1:10
if isprime(z(i,j))
cnt=cnt+1;
sm=sm+z(i,j);
end
end
end
cnt
sm
fprintf('there are %d prime numbers and their sum is %d',cnt,sm)

editor window screenshot: checks prime numbers and finds their sum

result window screenshot:

kindly comment for further elaboration..please like if you find it needfull...


Related Solutions

You can use any programming languages Using a random generator, compute 1000 integers between 1 and...
You can use any programming languages Using a random generator, compute 1000 integers between 1 and 1000. There will be duplicates in the array. Sort the array using bubble sort and merge sort. The two sorted arrays should agree. Then pick at random one element from your sorted array and use a binary search to find its position in the array.
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this new matrix to a file called “Assignment3_Question5.dat”.
Q.1: Use the NumPy’s random number generation to create an array of five random integers that...
Q.1: Use the NumPy’s random number generation to create an array of five random integers that represent summertime temperatures in the range 60–100, then perform the following tasks: a. Convert the array into the Series named temperatures and display it. b. Determine the lowest, highest and average temperatures. c. Produce descriptive statistics for the Series. Q.2: Given the following dictionary; temps = {'Mon': [68, 89], 'Tue': [71, 93], 'Wed': [66, 82], 'Thu': [75, 97], 'Fri': [62, 79]} perform the following...
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply...
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply Normalization: (X - Mean) / Deviation
Given a matrix ? (i.e., a 2D table) of positive integers of size ? × ?....
Given a matrix ? (i.e., a 2D table) of positive integers of size ? × ?. A robot starts at the top- left position ?[?, ?] and must reach the bottom-right position ?[?, ?]. From a position ?[?, ?], the robot can only go either right to ?[?, ? + ?] or down to ?[? + ?, ?]. Let us define the cost of a path the total values of integers in it. Find the least-cost path for the robot...
1. Write a python program to create a list of integers using random function. Use map...
1. Write a python program to create a list of integers using random function. Use map function to process the list on the expression: 3x2+4x+5 and store the mapped elements in another list. Now use filter to do sum of all the elements in another list. 2. Write a function that takes n as input and creates a list of n lists such that ith list contains first 10 multiples of i. 3. Write a function that takes a number...
Find the number of integers between 100 and 1000 that are
Find the number of integers between 100 and 1000 that are (i) divisible by 7  (ii) not divisible by 7      
In C 1- Use nested for loops to create an addition lookup table. Fill in an...
In C 1- Use nested for loops to create an addition lookup table. Fill in an array and print out the following table showing the sum of the row and column numbers 0-9. 0 1 2 3 4.. <- column numbers 1 2 3 4 5.. 2 3 4 5 6.. <- These nos. = Row + Column 3 4 5 6 7.. <- for example 7 = 3 + 4 4 5 6 7 8.. ... ^Row numbers 2-...
Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0.
This program is for C.Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0. Combine the elements of A + B to create two- dimensional array C = A + B. Display array A, B and C to the screen for comparison. (Note a[0] + b[0] = c[0], a[1] + b[1] = c[1], etc.)
DISCRETE MATH a. How many integers between 1 and 1000 are divisible by either 7 or...
DISCRETE MATH a. How many integers between 1 and 1000 are divisible by either 7 or 11? b . How many integers between 1 and 1000 have distinct digits? c .A student council consists of 15 students. Two council members always insist on serving on committees together. If they cannot serve together, they will not serve at all. How many ways can a committee of six be selected from the council membership? d. A set of five distinct computer science...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT