Professional Documents
Culture Documents
Lecture contents
Introduction to computers and computer programming
2
Computer Basics
Storage
A program is a set
of instructions
designed to solve
problems
4
Some computer terms
5
Some more computer terms
7
Computer Programs
8
1. /* This is a program in C. It prints out the message Hello World on the
computer terminal
2. */
3. #include <stdio.h>
4. void main()
5. {
7. printf("Hello World\n");
8. }
9
Key in the program
Source file
Compile program
Object file
Error?
Warning?
Link/load the program
Executable file
Doesn’t work?
Systems
engineering Define the problem
Analysis
Plan the solution
Design
Implement the solution
Code
Testing
Maintenance
11
1. Specify the problem requirements
find out what user wants
13
Calculate the cost of a bag of apples
14
1. /* This program calculate the cost of apples, given the quantity purchased and the cost per *
pound.
2. */
3. #include <stdio.h>
4. void main()
5. {
6. int quantity; /* apples bought in kg.*/
7. double unit_cost, total_cost; /* unit cost in £ per kg. total cost in £s */
8. printf("How many pounds of apples were bought?\n"); /* Ask for quantity purchased */
9. scanf("%d",&quantity); /* Get quantity from user */
10. printf("What is the cost per pound of apples?\n"); /* Ask for unit cost */
11. scanf("%lf",&unit_cost); /* Get unit cost from user */
12.
13. total_cost = quantity * unit_cost; /* Calculate the cost */
14. printf("The total cost of your apples is : %f\n",total_cost); /* display total cost */
15. }
15
Summary
16
Review Questions
A brief history of C
Variables
Integer arithmetic
/* Comments in C */
18