Knowee
Questions
Features
Study Tools

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

Question

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

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

Solution

Sure, here is a Python solution for the problem:

def calculateArraySum(arr):
    return sum(arr)

def calculateAbsoluteDifference(arr1, arr2):
    sum1 = calculateArraySum(arr1)
    sum2 = calculateArraySum(arr2)
    return abs(sum1 - sum2)

# Test the function
arr1 = [-100, -49, -87, 5, 6, 7, 0, 100, 37, 57]
arr

Similar Questions

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 statementGinny, an inquisitive mind fascinated by the intricacies of arrays, has posed a challenge for you. She needs a program that can identify and display the unique elements present in an array. Write a program that includes a function named findUniqueElements where the array is passed as an argument.Input format :The first line of input is an integer value 'N', representing the size of the array.The second line of input consists of N space-separated integers arr[i], representing the elements of the array.Output format :The output displays the integers, representing the unique elements identified within the array, separated by spaces.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ N ≤ 151 ≤ arr[i] ≤ 100Sample test cases :Input 1 :73 1 5 2 5 4 3Output 1 :1 2 4 Input 2 :155 2 7 1 4 9 8 6 3 2 5 10 7 12 100Output 2 :1 4 9 8 6 3 10 12 100 Input 3 :23 4Output 3 :3 4

Single File Programming QuestionProblem StatementAlex is creating a utility to evaluate a user's numerical input. The program calculates the absolute difference between the sum of digits at odd and even positions, where the first digit is considered position 1. Users enter a sequence of digits, and the program outputs the result.ExampleInput:5674Output:2Explanation:The sum of the even-position digits 6 and 4 is 10. In the odd position, the sum of digits 5 and 7 is 12. So, the absolute difference is |10-12| = 2.Input format :The input consists of an integer n.Output format :The output prints the difference between the sum of the odd and even position digits in the given integer.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases will fall under the following constraints:10 ≤ n ≤ 107Sample test cases :Input 1 :5674Output 1 :2Input 2 :1234567Output 2 :4Input 3 :10Output 3 :1Input 4 :10000000Output 4 :1

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

Single File Programming QuestionProblem StatementMithun is developing a program for a data collection tool that allows the user to input a series of positive integers until they enter a negative value. The program should dynamically allocate memory for an integer array to store these numbers using the new operator. The program should then calculate and display the sum and average of the entered integers. Write a program to accomplish this task.Note: This kind of question will help in clearing HCL recruitment.Input format :The input consists of positive integers separated by a space. It continues until a negative value is entered.Output format :The first line of the output displays the entered numbers.The second line displays the sum of the numbers.The third line displays the average of the entered numbers.Refer to the sample output for formatting specifications.Code constraints :numbers > 0Maximum number <=100Sample test cases :Input 1 :1 2 3 4 5 6 -1Output 1 :Numbers entered: 1 2 3 4 5 6 Sum of entered numbers: 21Average of entered numbers: 3.50Input 2 :10 20 30 40 50 60 70 80 90 100 -4Output 2 :Numbers entered: 10 20 30 40 50 60 70 80 90 100 Sum of entered numbers: 550Average of entered numbers: 55.00Note :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.

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.