Cp01 Intro
Cp01 Intro
CSF111
Computer Programming
Introduction
Teaching team
No labs on: Mar 29-30, Apr 5-6, Apr 19-20, May 3-4. Last lab: Jun 28.
This course is about
● Fundamentals of Programming
● From specification to implementation
● Software engineering principles
● Developing viable notional machines
Input
Program
🖥️
Output
Programming Languages
Programming is a creative,
collaborative activity!
Programming Languages
High-level languages
● C, C++, Java, Python, Haskell, Kotlin, Swift, …
○ hyp = sqrt(x*x + y*y)
● Do not rely on the underlying machine language
● Need a translator – a fairly complex software
● Much easier to read and understand for fellow humans
● Much easier to build meaningful abstractions
Translator (for our purposes, compiler)
Input
Program
🖥️
Output
Translator (for our purposes, compiler)
Input
Program Compiler
🖥️
Output
Our first program
Standard C libraries we need;
Details later
Input
#include <stdio.h>
int main() {
printf("My first program.");
🖥️
return 0;
}
Output
#include <stdio.h>
int main() {
printf("My first program.");
🖥️
return 0;
} Displays My first program.
on the console
Our second program You can add as many printf instructions
as you want. They will be executed one
after the other in the given sequence.
#include <stdio.h>
int main() {
printf("My second program.");
printf("BITS"); “%d” is a special format specifier which
acts as a placeholder for an integer value
printf("goa");
printf("%d", 42);
return 0; What is the output of this program?
}
My second program.
printf("BITS");
My second program.BITS
printf("goa");
My second program.BITSgoa
Program Line What we see
printf("%d\n", 12+4);
16
printf("%d\n", 12+4*2);
16
20
printf("%d\n", 10/2+3);
16
20
8
printf("%d\n", 10/(2+3));
16
“\n” is a special sequence that tells 20
printf to print a new line 8
2