Using <iostream> and <cmath> only Write a C++ program that ask the user for a no
ID: 3652241 • Letter: U
Question
Using <iostream> and <cmath> onlyWrite a C++ program that ask the user for a non-negative integer n and a double number x, (make sure you ask for input in this order, ask n first and then ask for x to make testing easier), then calculate:
f(n, x) = 1+x+x^2+ x^3 + ... + x^n
where x^i is x to the power of i.
There are many different ways of calculating this value, please implement the following methods.
use pow function defined in <cmath> library to assist computing f(n, x)
write your code without using any library function to compute f(n,x), optimize your code if necessary so that your code contains only one level of loop (no nested loop)
use pow function defined in <cmath> library to compute:
g(n, x), where g(n, x) = n+1 when x is 1; and g(n, x) = (1-x^(n+1))/(1-x) when x is not 1.
Explanation / Answer
#include #include using namespace std; int main() { int n; double x; coutn; coutx; if(x==1) coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.