CEG220: Introduction to C Programming for Engineers – I

Section 2

 

Homework for Week 5

 

  1. Writing functions
    1. that compute the nth Fibonacci number, where fibonacci (0) = 0, fibonacci(1) = 1. Recall that

fibonacci(n) = fibonacci(n-1) + fibonacci(n-2).

 

    1. write a function that computes the nth row of Pascal’s triangle.

 

  1. Enumerated types are integer values that have a user-defined significance. For example, I can define an enumerated type called ClassificationType that can have values Kingdom, Phylum, Class, Order, Family, Genus, Species. We define it this way: enum ClassificationType = { Kingdom, Phylum, Class, Order, Family, Genus, Species }; By default, Kingdom = 0, Phylum = 1, etc. You can also specify its values, but each value and name must be unique. We can define ClassificationType as: enum ClassificationType = {Kingdom = 1, Phylum = 10, Class = 3, Order = 12, Family = 4, Genus = 5, Species = 7};
    1. Define an enumerated type that expresses time zones
    2. Write a function that, given a raw time in GMT and a TimeZoneType, computes the time for that time zone
    3. Define an enumerated type that expresses computer platforms: UNIX, Windows, Macintosh, and Linux
    4. Write a function that performs byte-swapping on a short, integer, and long if the PlatformType variable == Windows.