1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.

Slides:



Advertisements
Similar presentations
A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Advertisements

Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Introduction to C Programming CE Lecture 1 Introduction to C.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
C. About the Crash Course Cover sufficient C for simple programs: variables and statements control functions arrays and strings pointers Slides and captured.
1 CSE 303 Lecture 8 Intro to C programming read C Reference Manual pp. Ch. 1, , 2.6, 3.1, 5.1, , , , Ch. 8 ; Programming.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Computer Science 210 Computer Organization Introduction to C.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
Instructor: Tina Tian. About me Office: RLC 203A Office Hours: Wednesday 1:30 - 4:30 PM or .
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
Programming With C.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Lecture 1 cis208 January 14 rd, Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
 Integers and Characters  Character Strings  Input and Output.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
1 Introduction to C Programming 計算機程式設計 2/22/2012 朱浩華.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
1 Lecture03: Control Flow 9/24/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
C is a high level language (HLL)
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Introduction to C Topics Compilation Using the gcc Compiler
UMBC CMSC 104 – Section 01, Fall 2016
Computer Science 210 Computer Organization
CSE 220 – C Programming C Fundamentals.
ECE Application Programming
Administrative things
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Introduction to C Topics Compilation Using the gcc Compiler
Getting Started with C.
Lecture2.
Administrative things
Visit for more Learning Resources
Computer Science 210 Computer Organization
Introduction to CS Your First C Programs
Introduction to C Topics Compilation Using the gcc Compiler
Programming Assignment #1 12-Month Calendar—
Your first C and C++ programs
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C EECS May 2019.
Introduction to C Topics Compilation Using the gcc Compiler
Course Outcomes of Programming In C (PIC) (17212, C203):
Administrative things
Administrative things
EECE.2160 ECE Application Programming
Getting Started With Coding
Presentation transcript:

1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C

What is Computer Programming? Give (lots of) simple instructions that tell the computer what to do. Combining these simple instructions is a computer program. What are these instructions written in? –A computer language –C, C++, C#, Java, Python, … 2

Endless examples of Computer Programs 3

Why Learn Programming?

Why Learned Programming Like solving a puzzle

7

8

Administrative things Instructor: Hao-Hua Chu, Office 518 – –Weekly office hours: Wed 2-3:30 pm. TA#1 陳世穎 – –Office hours: TBD TA#2 ??? Course URL – 10

Textbook (optional) C is a simple language, my slides ought to cover it. –Google to get additional examples. Optional textbook: “The C Programming Language, 2 nd Edition” by Kernighan & Ritchie –Authors are creators. 11

Goals You become a good C programmer! C syntax Standard libraries Programming for robustness and speed Understanding compiler 12

Topics Lect02: Control Flow Lect03: Functions Lect04: Pointers and Arrays Lect05: Complex Types Lect06: Memory Model Lect07: Performance Lect08: Preprocessor Lect09: Standard Input and Output Lect10: File and Variable- length Argument Lists Lect11: Threads and Synchronization Lect12: To Be a Master Programmer Lect13: C++ basics 13

Other things Can go fast (very fast for some students), so please-please stop and ask me questions Lecture: –1.5 HR lecture –1.5 HR in-class exercise & one-on-one Q&A (a bit worried about too many students) Diverse programming experiences among students –Advanced students can work on in-class exercise (at the end of the lecture slide) and/or homework 14

Programming Environment Codeblocks Use other editors or your choices 15

Ready to write your 1 st program? Get your accounts in RM 204 Find the Codeblocks program already on the computer 16

CodeBlocks: Compile and Run Run CodeBlocks Create a new project –File → New → Project –Select “Console application” –Click C → Next –Type in Project title: (e.g., “hello”) –Click finish Open and edit the main.c –File → Open –Find “main.c” Compile and run –Build → Build and Run 17

18

19

20

21

22

23

24

main.c: Hello World (delete the original program) #include int main() { printf("Hello World :)\n"); return 0; } 25

26

27

28

What Happened? Compile (Build → Build) –Compile “main.c” to machine code named “hello.exe” Run (Build → Run) –Execute the program “hello.exe” 29 main.c (Hello World) include /* printf() is declared in this header file. */ int main() /* Main point of execution */ { printf("Hello World :)\n"); /* Output “Hello World” to console */ return 0; /* Tell OS the program terminates normally */ }

main.c: Variables #include int main() { int a, b, c; a = 10; b = 20; c = a * b; printf("a = %d b = %d c = %d\n", a, b, c); return 0; } 30

31

printf(format string, val1, val2); –format string can include placeholders that specify how the arguments val1, val2, etc. should be formatted –%c : format as a character –%d : format as an integer –%f : format as a floating-point number –% : print a % character Examples double f = 0.95; printf("f = %f%\n", f * 100); More on printf 32

33

Even more on printf Placeholders can also specify widths and precisions –%10d : add spaces to take up at least 10 characters –%010d : add zeros to take up at least 10 characters –%.2f : print only 2 digits after decimal point –%5.2f : print 1 decimal digit, add spaces to take up 5 chars Examples int i = 95; double f = 0.95; printf("i = %d\n", i); printf("i = %10d\n", i); printf("i = %010d\n", i); printf("f = %f\n", f); printf("f = %.2f%\n", f * 100); printf("f = %10.2f%\n", f * 100); 34

Warning about printf printf is powerful, but potentially dangerous What does this code output? int i = 90; double f = 3; printf("f = %f i = %d\n", f); printf("f = %f\n", f, i); printf("i = %d f = %f\n", f, i); 35

main.c: Scanf #include int main() { int i; double f; scanf("%d", &i); scanf("%lf", &f); printf("Integer: %d Float: %2.2f\n", i, f); return 0; } 36

In-Class Exercise Write a program that calculates travel reimbursement for a pizza delivery person at a rate of NT$6.97 per kilometer. Your program should interact with the user in the following manner: (It is okay not to get the program right the first time. Look at the compilation errors and fix them.) KILOMETER REIMBURSEMENT CALCULATOR Enter beginning odometer readings=> Enter ending odometer reading=> You traveled kilometers. At $6.97 per kilometer, Your reimbursement is $