Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

image text in transcribed

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.

image text in transcribed

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

image text in transcribed

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.

image text in transcribed

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.

image text in transcribed

_______

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

4. Are there any disadvantages?

Answered: 1 week ago

Question

3. What are the main benefits of using more information technology?

Answered: 1 week ago

Question

start to review and develop your employability skills

Answered: 1 week ago