Question: 1.Write a program to compute different mathematical expressions in C: Write a pure function int sumNloop(int N) that computes sum of integers from 1 to

1.Write a program to compute different mathematical expressions in C:

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 sumNformula(int N) that uses the familiar formula to compute the same thing.

1.Write a program to compute different mathematical expressions in C: Write a

Write a pure function sumSquaresloop(int N) that computes the sum n^2 for integers 1 to N:

pure function int sumNloop(int N) that computes sum of integers from 1

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.

to N: Sum = 1+2+3+4+...+(n-1)+N Do this the obvious way by initializing

Now write a pure function sumCubesloop(int N) that computes the sum n^3 for integers 1 to N:

a sum to zero and then adding up the integers using a

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.

loop. Now write a pure function int sumNformula(int N) that uses the

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. Dont do error checking. Just let overflow happen for large N.

familiar formula to compute the same thing. Write a pure function sumSquaresloop(int

_______

Use ANSI-C syntax. Compile and run using the gcc environment. Do not mix tabs and spaces in the source file. Debug thoroughly.

n(n + 1) sum =- 2 Sum = 12+22+32+ ... +(n-1)2+n2 n(n + 1)(2n + 1) sum =- Sum = 13+23+33+ ... +(n-1)3+n3 (1 + 2) = uns C:\CSource>a Enter N -->75 sum i to N loop: 2850; formula: 2850 sum 1 to N**2 loop: 143450; formula: 143450 sum 1 to N**3 loop: 8122500; formula: 8122500 C:\CSource>

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!