Link to the DIT Home Page

Dublin Institute of Technology, School of Computing
Ciarán O'Leary

  Home -> Teaching -> DT249-1 Programming and Algorithms -> Notes -> Week 03
  DT249-1 Programming and Algorithms

Week 03


Learning Outcomes:

Upon completion of this class, you should be able to:

  1. Write programs which contain if statements.
  2. Write programs which contain switch statements.
  3. Distinguish between the appropriate uses for if and switch statements.
  4. Predict the behaviour of programs with if and switch statements.
  5. Write programs with iterative components.
  6. Create iteration in a program using a while loop.
  7. Create iteration in a program using a do..while loop.
  8. Create iteration in a program using a for loop.
  9. Distinguish between the appropriate uses for while, do..while and for loops.
  10. Predict the behaviour of programs with while, do..while and for loops.

Tasks

1.

Complete the tasks from last week.

 

2.

Download the code for this week's notes. Go through all the code, compiling and running each program separately. If you have any problems, ask the lab supervisor for help, or take a note of the problem and we can discuss it in next week's class.

The code is bundled into a ZIP file. This is a compressed file which contains all the separate source code files. To open this file and extract the contents, you can use the WinZip tool which is available in the lab, and is available for free download here.

Make sure to put all your code into a folder named week_3 in your programming folder on your u: drive.

 

3.

Write a program which reads in two integers and checks whether the first is evenly divisible by the second.

Call this program paa_ex_03_01.c and put it in your week_3 folder.

Please see sample solution here.

 

4. Write a program to input a number 1 - 7 from the keyboard. Your program should display the day of the week corresponding to the number (where 1 is Sunday, 2 is Monday etc.). If an incorrect number is entered, an error message must be displayed.

Call this program paa_ex_03_02.c and put it in your week_3 folder.

Please see sample solutions here, here, here (incorrect), here and here.

 

5. Write a program to sum (add up) all the odd numbers between 0 and 100 using a while loop.

Call this program paa_ex_03_03.c and put it in your week_3 folder.

Please see sample solutions here and here.

 

6. Write a program to sum (add up) all the odd numbers between 0 and 100 using a for loop.

Call this program paa_ex_03_04.c and put it in your week_3 folder.

Please see sample solutions here, here, here, here and here.

 


Further Reading

Chapters 5 & 6 of Paul Kelly book.

 

Hit Counter  [Home][School of Computing][Dublin Institute of Technology]