Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program has to be written in C 1. Write a pure function int sumNloop (int n) that computes sum of integers from 1 to

The program has to be written in C

image text in transcribed

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 sumNformula (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. 2 sum = ((n + 1) in(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. 2850 C:\CSource>a Enter N -->75 sum 1 to N loop: 2850; formula: sum 1 to N**2 loop: 143450; formula: sum 1 to N**3 loop: 8122500; formula: C:\CSource> 143450 8122500

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

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago