Question: IN C Please 1. Write a pure function int sumNloop (int n) that computes sum of integers from 1 to N: Sum = 1+2+3+4+...+(n-1)+N Do

 IN C Please 1. Write a pure function int sumNloop (int

n) that computes sum of integers from 1 to N: Sum =

IN C Please

1. Write a pure function int sumNloop (int n) that computes sum of integers from 1 to N: Sum = 1+2+3+4+...+(n-1)+N Do this the obvious way by initializing a sum to zero and then adding up the integers using a loop. Now write a pure function int sum formula (int n) that uses the familiar formula to compute the same thing. n(n+1) sum = 2 2. Now write a pure function sumSquaresloop (int n) that computes the sum n2 for integers 1 to N: Sum = 12+22+32+ +(n-1)2+n2 Do this the obvious way by initializing a sum to zero and then adding up the squares of integers using a loop. Now write a pure function int sumSquaresformula (int n) that uses the formula to compute the same thing. sum = n(n + 1)(2n + 1) 6 3. Now write a pure function sumCubesloop (int n) that computes the sum n3 for integers 1 to N: Sum = 13+23+33+ ... +(n-1)3+n3 Do this the obvious way by initializing a sum to zero and then adding up the cubes of integers using a loop. Now write a pure function int sumCubesformula (int n) that uses the formula to compute the same thing. sum = ("(1971) n(n + 1) 2 4. Write a main function that asks the user for N, and then prints out six sums as computed by each of the above six functions. Of course, the corresponding pairs should compute the same value. Do all I/O in main. The functions themselves should not do I/O. Don't do error checking. Just let overflow happen for large N

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!