-
Please help!!!
i have a university assignment to do in C++ and i dunno what code to write can anyone help me? :confused:
this is my assignment:
develop a C program to approximately calculate the value of e(to the power x) applying this followong infinite series:
e(to power x) = (sum of sign, with infinity above it, and (n=o below) (x(to power n/n factorial)
in the range n=0,1...,10, and x=0.8
what is this? please help!
-
How about starting with a function to calculate factorial(n)
Since math.h already has a pow() function, the rest is just a loop
> i have a university assignment to do in C++
> develop a C program
Make your mind up - which is it?
-
argh
Ok ur talkin to someone whos never done programming before. This is a random compulsory assignment. Iv been told we are programming in c++, and the bit i wrote was copied word for word from the sheet. so i assume they mean write a c++ program for ....
so i need to start form the beginning basically...
-
No basic instruction in C++ at all - like how to even compile the simplest of "hello world" programs?
Do you have a compiler set up which you can use?
-
I know the basic stuff u start with, like
#include <stdio.h>
main()
{
but they dont tell me about how to write the code for this particular equation...
-
Short of handing your homework to you on a plate (it's not likely to happen), this is as far as I can go showing you the way.
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x = 0.8;
double sum = 0.0;
for ( int n = 0 ; n <= 10 ; n++ ) {
double pow_term = pow(x,n);
// double fact_term = .....
cout << "n=" << n << " pow(x,n)= " << pow_term << endl;
sum = sum + pow_term /* / fact_term */;
}
cout << "Sum = " << sum << endl;
return 0;
}
All you need do is uncomment the fact_term bits and work out how to calculate factorial(n)