Solution: Here is your answer hope this helps you.
Consider calculating the sum of the squares of the numbers 1 to
n. Now calculate
two intermediate lists, one of which is the list 1 to n, and the
second is the
squares of 1 to n
we know in haskell how to write the code:
sumSquare :: Int -> Int
sumSquare n = sum (map square [1..n])
square :: Int -> Int
square x = x * x
It is also possible to write a function that computes the sum of
the squares of
the numbers 1 to n without using any intermediate lists. For
example:
sumSquare :: Int -> Int
sumSquare n = sumSq' 1
where
sumSquare' x = if x > n
then 0
else square x + sumSquare' (x+1)
So you know the effcient the program is arguably less modular and
harder to
understand specifically because the program no longer expresses the
natural
pipeline structure of this calculation
Oz programming Write two functions which compute the sum of squares of the integers stored in...
C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...
Solve using Matlab
Write a simple loop to list the squares of the first 10 integers. Using a simple "while" loop, write a script to sum the series 1 + 2 + 3 + ... such that the sum is as large as possible without exceeding 100. The program should display how many terms are used in the sum. Write a script that takes as input an integer n and creates the n*n matrix A with (ij)th component given by...
C programming Write a function that accepts an array of integers as an input, and output the sum of all values and the multiplication of all values. e.g. Suppose that the array contained the following values: 1 2 3 -4 5. The function should calculate and output the sum of values (i.e. 1+2+3+(-4)+5=7) and the multiplication of all values (i.e. 1*2*3*-4*5=-120). Start by carefully writing the function prototype - put some thought into this. Think about the good programming habits,...
C++
Write a program to calculate the sum of two matrices that are
stored inside two-dimensional arrays. Your program should include
three functions: one for getting input data, one for calculating
the sum of matrices, and one for printing the result.
a) Function inputMatrix: This Function prompts the user to enter
the data and stores data inside two-dimensional array.
b) Function addMatrices: This function calculatesthe sum result
of two matrices.
c) Function printMatrix: This function prints the matrix to
screen....
Programming in Java Q: Build an expression tree for a given postfix expression. Then compute the value of the expression by doing an in-order traversal of the expression tree. For example: Your output should print the following: o The input is: "Expression" o The inorder traversal is: "inorder traversal" o The output of the expression is: "output" Please print the output in the same format. (example shown below) The input is: 1 68+ The inorder traversal is: 168 The output...
Write an application that uses parallelism to compute the sum of the integers in an array of size 100000. You can populate the array with random numbers and your application should display the sum.
C++ Programming question
Problem: 5. Write a program that reads in a list of integers into an array with base type int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input, the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be...
coding in c programming
Functions & Arrays Q1) The greatest common divisor (GCD) of two Integers (of which at least one is nonzero) is the largest positive integer that divides the numbers. Write a C function ged that accepts two integers and returns 1 if both the integers are zero, otherwise it returns their GCD. Write a C program (that includes the function ged) which accepts two integers and prints their GCD. Sample output: Enter two integers: 0 0 At...
please explain each line of code! ( in python
)
1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Your function should take one parameter, root node. You may assume that the tree only contains integers. You may not call any methods from the LinkedBinaryTree class. Specifically, you should traverse the tree in your function def binary tree even sum (root): Returns the sum of al1 even integers in the binary tree 2....
C programming question! Write a program that reads two numbers and finds the greater one. The input is two integers and the output will be a single line “The maximum of ? and ? is ?.”, where ? and ? are the input values and ? is the maximum of ? and ?. If ? and ? are equal, ? will be equal to both of them. Example of input: 10 20 Corresponding output: The maximum of 10 and 20...