C exercises - PowerPoint PPT Presentation

About This Presentation
Title:

C exercises

Description:

Recursive algorithms are very common in many computations like: series expansion ... Chronometer. A class which display the elapsed time ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 16
Provided by: monica69
Category:

less

Transcript and Presenter's Notes

Title: C exercises


1
C exercises
2
Recursive programming
  • Recursive algorithms are very common in many
    computations like
  • series expansion
  • tree (directory) navigation
  • search, sort etc (divide and conquer)
  • integer arithmetic

3
Factorials
Base case known solution
double fact(int n) if (nlt1) return 1.
else return double(n)fact(n-1)
Recursive call progress toward base case proof
by induction
4
Other Recursive algorithms
  • Greatest Common Divisor
  • gcd(A,B)gcd(A-B,B) gcd(B,A mod B)
  • Zero of a function (bisection algorithm)
  • search in ordered collections (binary search)
  • operations on compound objects
  • print an integer in base N
  • void pi(int n, int b) if(ngtb) pi(n/b,b) cout
    ltltnb

5
HelloWorld
  • Print sin(x) xminltxltxmax
  • print first 10 factorials
  • do the running sum of the first 1000 integers and
    print it each 20
  • find the zero of a function in an interval using
    a bisection algorithm
  • find clusters above noise in a linear input

6
Chronometer
  • A class which display the elapsed time
  • implement correctly the functions of the two
    buttons
  • (re)-start
  • stop
  • reset
  • lap (read elapsed time without stopping watch)

7
Statistical bin
  • Return sum, average and rms of the inputs
  • implement operations among bins with correct
    error propagation

8
Multiplexer
  • A system which switches among different
    algorithms depending on some predefined input
  • to be written without a single switch or if
    statement

9
Histograms
  • Book, fill, print 1d,2d hist
  • operate on them
  • name them

10
CLHEP
  • Use vectors
  • use rotations
  • use Lorenz-Vectors
  • Jet algorithm

11
Estrazioni del lotto
  • Extract 5 out of 90 numbers

12
Tombola
  • Full Tombola including extraction and card checks

13
Shapes
14
Shapes and visitors
  • Area an perimeters
  • Sort shapes by area

15
Daq hardware
Write a Comment
User Comments (0)
About PowerShow.com