exercises

up

next

 

chapter 1 chapter 2 chapter 3

Home keywords c bibliography

 

exercises chapter 2

    Exercise 1:

Probably you do not want to see it anymore, but transform the following expression

for (i=1;i<=20;i++) cout << i << "\t" << i*(i-1) << "\n";

(as part of the whole program, of course)

  1. into a while loop

  2. into a do-while loop.

    Exercise 2:

For a physicist an often used value to describe decay processes is euler's number e. In lack of this value you decide to calculate it by an expansion series:

e = Sn=0..¥(1/n!)

(n!=1*2*3*...*n and 0!=1)

Being lucky that this series converges rather fast, you are going to write a program which evaluates e this way up to the order n=10. Generate an output of the calculated value for each order to see the approach of the series to e. Use the data type double to store the value for euler's number.

    Exercise 3:

Calculate (and print to the screen) the prime numbers between 3 and 100.

 

solutions

 

 

email me: Daniel Schürmann