Knowee
Questions
Features
Study Tools

Single File Programming QuestionProblem statementJerzy, a devoted mathematician, is looking to develop a program that addresses a unique challenge involving prime numbers and 2D arrays.The objective of this program is to efficiently identify prime numbers within a 2D array and calculate their cumulative sum.The program will include two key functions:isPrime(num): This function will assess whether a given integer num is a prime number.sumOfPrimes(rows, cols, arr): This function will calculate and return the sum of all prime numbers found within a 2D array arr, which has dimensions specified by rows and cols. Input format :The first line of input consists of two integers r and c, representing the number of rows and columns in the 2D array.The next r lines of input consist of c integers each, separated by space, representing the elements of the 2D array.Output format :The output displays a single integer, representing the sum of all prime numbers in the given 2D array.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ r , c ≤ 101 ≤ elements ≤ 100Sample test cases :Input 1 :2 32 3 76 9 8Output 1 :12Input 2 :3 42 3 4 57 8 9 1011 12 13 14Output 2 :41Input 3 :5 52 3 4 5 96 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 25Output 3 :100Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Question

Single File Programming QuestionProblem statementJerzy, a devoted mathematician, is looking to develop a program that addresses a unique challenge involving prime numbers and 2D arrays.The objective of this program is to efficiently identify prime numbers within a 2D array and calculate their cumulative sum.The program will include two key functions:isPrime(num): This function will assess whether a given integer num is a prime number.sumOfPrimes(rows, cols, arr): This function will calculate and return the sum of all prime numbers found within a 2D array arr, which has dimensions specified by rows and cols. Input format :The first line of input consists of two integers r and c, representing the number of rows and columns in the 2D array.The next r lines of input consist of c integers each, separated by space, representing the elements of the 2D array.Output format :The output displays a single integer, representing the sum of all prime numbers in the given 2D array.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ r , c ≤ 101 ≤ elements ≤ 100Sample test cases :Input 1 :2 32 3 76 9 8Output 1 :12Input 2 :3 42 3 4 57 8 9 1011 12 13 14Output 2 :41Input 3 :5 52 3 4 5 96 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 25Output 3 :100Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python solution for the problem:

def isPrime(num):
    if num <= 1:
        return False
    if num == 2:
        return True
    if num % 2 == 0:
        return False
    for i in range(3, int(num**0.5)+1, 2):
        if num % i == 0:
            return False
    return True

def sumOfPrimes(rows, cols, arr):
    sum_primes = 0
    for i in range(rows

Similar Questions

erzy, a devoted mathematician, is looking to develop a program that addresses a unique challenge involving prime numbers and 2D arrays.The objective of this program is to efficiently identify prime numbers within a 2D array and calculate their cumulative sum.The program will include two key functions:isPrime(num): This function will assess whether a given integer num is a prime number.sumOfPrimes(rows, cols, arr): This function will calculate and return the sum of all prime numbers found within a 2D array arr, which has dimensions specified by rows and cols. Input format :The first line of input consists of two integers r and c, representing the number of rows and columns in the 2D array.The next r lines of input consist of c integers each, separated by space, representing the elements of the 2D array.Output format :The output displays a single integer, representing the sum of all prime numbers in the given 2D array.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ r , c ≤ 101 ≤ elements ≤ 100Sample test cases :Input 1 :2 32 3 76 9 8Output 1 :12Input 2 :3 42 3 4 57 8 9 1011 12 13 14Output 2 :41Input 3 :5 52 3 4 5 96 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 25Output 3 :100Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks : 10Negative Marks : 0

Single File Programming QuestionProblem statementRaj is working on a data analysis project and needs help creating a program that processes a 2D array. This program includes functions to calculate the average value of each row in a 2D array. The program should consist of several functions:calculateRowAverage(cols, row): Calculates the average of a single row in a 2D array.calculateAverages(rows, cols, arr, averages): Computes and stores the averages for each row in the 2D array.displayAverages(rows, averages): Displays the row number and its average value.Input format :The first line of input consists of two integers, rows and cols, representing the dimensions of the 2D array.The second line of input consists of the elements arr[i] of the 2D array, where each element is a double.Output format :The output displays the average value of each row as a double datatype value, rounded off two decimal points in the specified format:Average of each row:Row 1: [row1_avg]Row 2: [row2_avg]Row 3: [row3_avg]Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ rows and cols ≤ 51.0 ≤ arr[i] ≤ 5.0Max_Rows and Cols = 100Sample test cases :Input 1 :3 31.7 2.9 3.54.2 5.7 6.87.2 8.1 9.6Output 1 :Average of each row:Row 1: 2.70Row 2: 5.57Row 3: 8.30Input 2 :2 26.8 1.25.6 8.9Output 2 :Average of each row:Row 1: 4.00Row 2: 7.25Input 3 :5 52.2 3.8 4.3 5.8 9.26.7 7.1 8.8 9.2 10.711.7 12.8 13.7 14.3 15.316.2 17.4 18.2 19.2 20.121.3 22.7 23.4 24.3 25.7Output 3 :Average of each row:Row 1: 5.06Row 2: 8.50Row 3: 13.56Row 4: 18.22Row 5: 23.48

Single File Programming QuestionProblem statementTheo, an aspiring mathematician, has presented you with a challenge. He wants you to create a program that calculates the absolute difference between the sum of two arrays.Create a program to find the absolute difference between two arrays with a function named calculateArraySum and calculateAbsoluteDifference where the array is passed as an argument.Input 10-100 -49 -87 5 6 7 0 100 37 5710-100 -75 -48 -86 -98 98 97 98 67 100Output 77ExplanationTwo arrays with 10 elements each are given as input.The first array has elements: -100, -49, -87, 5, 6, 7, 0, 100, 37, 57, and the sum of the first array is - 24.The second array has elements: -100, -75, -48, -86, -98, 98, 97, 98, 67, 100, and the sum of the second array is 53.The absolute difference of the sum is calculated by subtracting the second array from first array |-24 - 53| = 77, and the result is printed.Input format :The first line of input is an integer value 'N1', representing the number of elements in the first array.The second line of input consists of N1 space-separated integers arr1[i], representing the elements of the first array.The third line of input is an integer value 'N2', representing the number of elements in the second array.The fourth line of input consists of N2 space-separated integers arr2[i], representing the elements of the second array.Output format :The output displays a single integer the absolute difference between the sums of the elements in the two arrays.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ N1, N2 ≤ 10-100 ≤ arr1[i], arr2[i] ≤ 100Sample test cases :Input 1 :35 8 332 6 4Output 1 :4Input 2 :6-2 5 0 8 -1 364 -3 2 7 1 6Output 2 :4Input 3 :10-100 -49 -87 5 6 7 0 100 37 5710-100 -75 -48 -86 -98 98 97 98 67 100Output 3 :77

Single File Programming QuestionProblem StatementKrish is a computer science student who loves solving challenging problems. Recently, he came across an interesting problem related to arrays. The problem requires Krish to find all pairs of elements in a given array whose sum equals a specific target value. Write a program for Krish that takes an array of integers and a target sum as input. The program should print all pairs of elements from the array whose sum equals the target sum. If no such pairs are found, it should print "Not found".ExampleInput:5 // number of elements10 20 30 40 50 // elements60 // target sumOutput:10 5020 40Explanation: The pair with 60 as sum are 20 + 40 = 60 and 10 + 50 = 60.Input format :The first line consists of an integer N, representing the number of elements in the array.The second line consists of N space-separated integers, representing the elements of the array.The third line consists of an integer M, representing the target sum.Output format :For each pairs found, print two integers separated by a space, whose sum equals the target sum.If no such pairs are found, print "Not found".Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases will fall under the following constraints:2 ≤ N ≤ 251 ≤ Each element ≤ 1003 ≤ M ≤ 200Sample test cases :Input 1 :32 3 65Output 1 :2 3Input 2 :510 20 30 40 5060Output 2 :10 5020 40Input 3 :42 3 4 78Output 3 :Not foundInput 4 :310 6 410Output 4 :6 4

Single File Programming QuestionProblem Statement:Thiru is working on a grading system for his class of students. He needs a program that takes input for student scores, inserts a new score at the beginning and end of the existing scores, and then displays the modified list of scores.Write a program to help Thiru achieve this.Input format :The first line of input is an integer, the value n, indicating the number of elements in the array.The second line of input consists of n space-separated integers, representing the elements of the array arr[i].The third line of input consists of two integers M and P, representing the value to be inserted at the beginning and ending of the array, separated by a space.Output format :The output is a single line containing n + 2 space-separated integers, which represent the modified array after inserting the element at the beginning and ending of the existing scores.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases will fall under the following constraints:1 ≤ n ≤ 101 ≤ arr[i] ≤ 1001 ≤ M, P ≤ 100Sample test cases :Input 1 :53 4 5 6 72 8Output 1 :2 3 4 5 6 7 8 Input 2 :14590 78Output 2 :90 45 78 Input 3 :1098 37 48 28 16 18 20 100 25 131 19Output 3 :1 98 37 48 28 16 18 20 100 2

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.