2023 Spring Computer Programming 1 Lecture01 Hello World
2023 Spring Computer Programming 1 Lecture01 Hello World
C Programming
Lecture 1 – Introduction
2022 Spring, CSE2003/AIE2050
Sogang University
CSE2003/AIE2050 S'23 1
Team
• Instructor
• Prof. Joo Ho Lee (AS818, jhleecs@sogang.ac.kr)
• 3 Credits
• Exam
• Date and time will be announced on the cyber campus.
CSE2003/AIE2050 S'23 4
Exercise & Programming Assignments
• Assignments are not graded, but we will give support and solutions.
CSE2003/AIE2050 S'23 5
Grading
• Exam (95 %)
• Midterm & final exams (45% and 50%, individually)
• Homework (0%)
• Programming and pen & paper assignments
• Relevant to exams
• Attendance (5%)
• Your attitude and attendance.
CSE2003/AIE2050 S'23 6
Cheating
• Exam modality
• Offline, the place would be announced one week before.
CSE2003/AIE2050 S'23 7
References
CSE2003/AIE2050 S'23 8
Definition of Word “Computer” before 1900
• Timelines
• Fibonacci (1200), Descartes (1620), Fermat (1630), Pascal (1650), Newton (1680),
Leibniz (1680), Euler (1750), Industrial Revolution (1760~1820), Gauss (1800),
Germain (1810), Galoise (1830)
• Mechanically operated
• A programmable device
• CPU: perform a given instruction like variable load, store and arithmetic
operation.
Abstract CSE2003/AIE2050
overview of “Analytic
S'23
machine” 13
How computer works?
Result Buffer
Program
load 3 to the result buffer
Counter
store the result buffer to variable 0
CPU
load 4 to the result buffer
store the result buffer to variable 1
slot1 slot2
load variable 0 to CPU slot 0
load variable 1 to CPU slot 1
addition
Memory
store the result buffer to variable 0
Variable 0
instruction, variable, constant
Variable 1
Instruction series (program)
CSE2003/AIE2050 S'23 14
Programming
• Programming language
• A notation about data and computation instruction steps
CSE2003/AIE2050 S'23 15
C Programming Language
Machine-executable
CSE2003/AIE2050 S'23 16
Computer & Program
Program
You
CSE2003/AIE2050 S'23 17
https://www.restaurantowner.com/public/Chef-Training-Managing-the-Recipes-and-the-Yield.cfm
Program Codes
• Computing tasks
• Mathematical: solving a systems of equations, finding the roots of a polynomial
• Others.
CSE2003/AIE2050 S'23 18
Executable Program
CSE2003/AIE2050 S'23 19
Program “Hello World”
#include < stdio.h >
int main(void) {
printf("Hello World\n");
puts("Hello World\n");
return 0;
CSE2003/AIE2050 S'23 20
/* Begin with comments about file contents */
CSE2003/AIE2050 S'23 22
The #include Macro
CSE2003/AIE2050 S'23 23
Program 2: Add Two Numbers
#include <stdio.h>
int add(int, int);
int main() {
int a, b, sum;
a = 10;
b = 5;
sum = add(a, b);
printf("%d+%d = %d\n", a, b, sum);
return 0;
}
int add(int a, int b) {
return a + b;
}
CSE2003/AIE2050 S'23 24
Variables in Program?
• Very different from variables in mathematics
• Variable in math: some value that satisfy conditions
• y=2, x = 2x-y-1, so x is 1.5
CSE2003/AIE2050 S'23 25
Declaring Variables
• Must declare variables before use
• Variable declaration:
int n;
float phi;
CSE2003/AIE2050 S'23 26
Initializing Variables
• Uninitialized, variable assumes a default value
• Variables initialized via assignment operator:
n=3
• Can initialized at declaration:
float phi = 1.6180339887;
• Can declare/initialize multiple variables at once:
int a,b,c = 0, d = 4;
CSE2003/AIE2050 S'23 27
Arithmetic Expressions
• A simple statement:
b=a+5*a/(b-2);
CSE2003/AIE2050 S'23 28
Order of Operations:
CSE2003/AIE2050 S'23 29
Assume x=3.0 and y=4.0. Evaluate the statement
float z = x+4*x/(y-2);
3. Evaluate addition
float z = x+6.0; → float z = 9.0;
float z = (x+4*x)/(y-2);
Order of Operations
CSE2003/AIE2050 S'23 30
Function Prototypes
• Function prototypes:
int isEven(int); or int isEven(int n);
CSE2003/AIE2050 S'23 31
Function Prototypes
CSE2003/AIE2050 S'23 32
The main() Function
• return 0;
exits the function, returning value 0 to caller
CSE2003/AIE2050 S'23 34
Function Definitions
Function declaration
{
declare variables;
Program statements;
}
• Must match prototype (if there is one)
• Variable names don’t have to match
• No semicolon at end
• Curly braces define a block – region of code
• Variables declared in a block exist only in the block
• Variable declarations before any other statements
CSE2003/AIE2050 S'23 35
Console I/O
• Stdout, stdin: console output and input stream
(ex. screen input and output in command prompt)
CSE2003/AIE2050 S'23 37
Reference
• https://en.wikipedia.org/wiki/Pascal%27s_calculator
• https://en.wikipedia.org/wiki/Stepped_reckoner
• https://en.wikipedia.org/wiki/Analytical_Engine
• https://en.wikipedia.org/wiki/Difference_engine
• https://www.youtube.com/watch?v=K6NgMNvK52A
CSE2003/AIE2050 S'23 39