2007年11月9日 星期五

the sum of the odd numbers or even numbers

Write a complete Java program that uses a for loop to compute the sum of the even numbers and the sum of the odd numbers between 1 and 25.

Source code and answer:


Taylor polynomials: sin(x)

1. (50) Write a Java program to calculate the sin function as follows:
sin(x)=x - x 3/ 3!+ x5/ 5! - x7/7! ...

Source code:






























執行結果:

Exponential Function

Do Project 7 of Chap. 3. (2nd ed. & 3rd ed.) or Project 4 (1st ed.)

Hint: You don't have to use nested loops.

Source code:














after running
x = 2
n = 1















n = 10
















n = 50















n = 100















由程式的計算結果證明,n越大其e^x越接近精確值e^2 = 7.389056099.....