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.
Write a pure function sumSquaresloop(int N) that computes the sum n^2 for integers 1 to N:
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.
Now write a pure function sumCubesloop(int N) that computes the sum n^3 for integers 1 to N:
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.
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.
_______
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started