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 04
  DT249-1 Programming and Algorithms

Week 04


Learning Outcomes:

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

  1. Create arrays of primitive types to store data.
  2. Create arrays of more than one dimension.
  3. Clearly describe the reasons for using arrays.
  4. Select the appropriate data structure for a given problem.
  5. Use arrays of characters as strings.
  6. Perform operations such as copy, compare and concatenate of character strings.
  7. Create arrays of strings.
  8. Explain how C treats character arrays as strings.

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_4 in your programming folder on your u: drive.

 

3. Write a program to read in 15 numbers and display them on the same line separated by semi-colons. Use loops and arrays.

Name the program paa_ex_04_01.c.

See sample solution here.

 

4. Rewrite the program so that the numbers are displayed in reverse order.

Name the program paa_ex_04_02.c.

See sample solution here.

 

5. Write a program which will display a suduko square (9 * 9 ints), with a 0 in each square. You should then prompt the user to enter a number into a square identified by its row and column. Users should be continuously prompted until the square is full. Each time a new number is added, the square should be redrawn.

Name the program paa_ex_04_03.c.

See sample solution here.

 

6. Write a program which asks the user to enter their full name and then prints out their first name and surname separately.

(Hint: use the fact that the string is an array of characters, and the names are separated by a space character.)

Name the program paa_ex_04_04.c.

See sample solution here.

 

7. Write a program to allow the user enter 5 countries and their capital cities. When everything has been entered, the user is prompted for a country. The capital city of that country is then printed out.

Name the program paa_ex_04_05.c.

See sample solution here.

 


Further Reading

Chapters 7 and 10 of Paul Kelly book

 

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