CSE1301 Computer Programming Lecture 4: C Primitives I.

Slides:



Advertisements
Similar presentations
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University.
1 CSE1301 Computer Programming Lecture 5 C Primitives 2.
Introduction to C Programming CE Lecture 1 Introduction to C.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
1 CSE1301 Computer Programming Lecture 9 Selection.
Three types of computer languages
1 CSE1301 Computer Programming Lecture 10: Iteration (Part 1)
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?
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1)
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.
C programming Language and Data Structure For DIT Students.
The C Programming Lecture 24.
C PROGRAMMING LECTURE C-language Computer Fundamentals.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
Computer Science 210 Computer Organization Introduction to C.
COMPUTER SCIENCE I C++ INTRODUCTION
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANCI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
CSE 2541 – Advanced C Programming Instructor: Yang Zhang
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1) Linda M c Iver.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
CSE 2541 – Advanced C Programming. Course info Prereq – CSE 2221 or CSE 222 Co-req – CSE 2231 Website
1 CSE1301 Computer Programming Lecture 12 Functions (Part 1)
1 Why C? History of C Generic C Program Structure Variables –Type and Name –Assignment Operator Simple I/O –scanf/printf Today’s Material.
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.
Khalid Rasheed Shaikh Computer Programming Theory 1.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
CMPE13Cyrus Bazeghi 1 Chapter 11 Introduction to Programming in C.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
小型系統 心情 vs. 古典樂 心情 vs. 古典樂 浪漫求籤系統 美食導航系統 季潔亭雅鈺熒岱芸 美食導航系統 楊氏音樂模擬大會考人瑋 若維 芷萱 伽倩 楊氏音樂模擬大會考 麥當勞熱量計算系統 火星文困擾你嗎 ? 火星文困擾你嗎 ? 歌詞知多少 - 挑戰你的腦容量英琪 日馨 青雪 鈺娟.
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 C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
CSE1301 Computer Programming Lecture 2: Introduction to C Joselito (Joey) Chua
From Algorithms to Programs Both are sets of instructions on how to do a task Algorithm: –talking to humans, easy to understand –in plain (English) language.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
CSCE 206 Structured Programming in C
Computer Science 210 Computer Organization
C Programming Hardik H. Maheta.
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.
History of ‘C’ Root of the morden language is ALGOL It’s first
ICS103 Programming in C Lecture 3: Introduction to C (2)
Introduction to C Topics Compilation Using the gcc Compiler
Getting Started with C.
Introduction to C Programming Language
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANSI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
CSI 121 Structure Programming Language Lecture 10: Iteration (Part 1)
Computer Science 210 Computer Organization
Chapter 11 Introduction to Programming in C
CSI 121 Structured Programming Language Lecture 5: C Primitives 2
CSI 121 Structured Programming Language Lecture 13 Functions (Part 1)
Govt. Polytechnic,Dhangar
Introduction to C Topics Compilation Using the gcc Compiler
CSI 121 Structure Programming Language Lecture 9 Selection
B. Ramamurthy University at Buffalo
A programming language
Introduction to C Topics Compilation Using the gcc Compiler
Getting Started With Coding
Presentation transcript:

CSE1301 Computer Programming Lecture 4: C Primitives I

Topics History of C Structure of a C program Values and variables Expressions Function calls Comments printf(“Hello World”);

Machine Language etc...

From Algorithms to Programs Both are sets of instructions on how to do a task Algorithm: –talking to humans, easy to understand –in plain (English) language Program: –talking to computer (compiler) –can be regarded as a “formal expression” of an algorithm

High-Level Language Compilers and linkers translate a high level program into executable machine code. #include int main() { printf(“Hello World”); return 0; } Source code Executable code etc...

Why C? Flexible language: –Structured language –Low level activities possible Standard library exists, allowing portability –See D&D 2/e Appendix B (web links in D&D 3/e) –Forouzan & Gilberg Appendix F It can produce lean and efficient code Wide availability on a variety of computers Widely used

History of C CPL Combined Programming Language (Barron et al., 1963) BCPL Basic CPL (Richards, 1969) B (Thompson, 1970) C K&R C (Ritchie, 1972) ANSI C American National Standards Institute C (X3J11, 1989) C99 (JTC1/SC22/WG14, ISO/IEC 9899, 1999)

Basic Structure of a C Program output “Hello World!” Algorithm: #include int main() { printf(“Hello World!”); return 0; } C Program: Example: Hello World

Basic Structure of a C Program (cont) #include int main() { printf(“Hello World!”); return 0; } C Program : Example: Hello world Includes standard input/output library of procedures. Read: “Hash-include”

Basic Structure of a C Program #include int main() { printf(“Hello World”); return 0; } C Program: Curly braces mark the beginning and end of a block of instructions. Example: Hello World

Basic Structure of a C Program #include int main() { printf(“Hello World”); return 0; } C Program: Instruction (function call) to output “Hello World” Example: Hello World

Basic Structure of a C Program #include int main() { printf(“Hello World”); return 0; } C Program: “Statements” (lines of instructions) always end with a semi-colon ( ; ) Example: Hello World

int main() { return 0; } Example -- Count to 10 Print out numbers 0 to 9 set count to 0 while ( count is less than 10 ) { output count add 1 to count }

#include int main() { return 0; } Example -- Count to 10 (cont) Print out numbers 0 to 9 set count to 0 while ( count is less than 10 ) { output count add 1 to count }

#include /* Print out numbers 0 to 9 */ int main() { return 0; } Example -- Count to 10 (cont) Print out numbers 0 to 9 set count to 0 while ( count is less than 10 ) { output count add 1 to count } Comment

#include /* Print out numbers 0 to 9 */ int main() { int count; return 0; } Example -- Count to 10 (cont) Print out numbers 0 to 9 set count to 0 while ( count is less than 10 ) { output count add 1 to count } Variable declaration

#include /* Print out numbers 0 to 9 */ int main() { int count; count = 0; while ( count < 10 ) { printf(“%d\n”, count); count=count+1; } return 0; } Example -- Count to 10 (cont) Print out numbers 0 to 9 set count to 0 while ( count is less than 10 ) { output count add 1 to count }

#include /* Print out numbers 0 to 9 */ int main() { int count; count = 0; while ( count < 10 ) { printf(“%d\n”, count); count=count+1; } return 0; } Example -- Count to 10 (cont) Print out numbers 0 to 9 set count to 0 while ( count is less than 10 ) { output count add 1 to count } Assignment of a value (right expression) to a variable (left).

#include /* Print out numbers 0 to 9 */ int main() { int count; count = 0; while ( count < 10 ) { printf(“%d\n”, count); count=count+1; } return 0; } Example -- Count to 10 (cont) Print out numbers 0 to 9 set count to 0 while ( count is less than 10 ) { output count add 1 to count } No semi- colon here!

#include /* Print out numbers 0 to 9 */ int main() { int count; count = 0; while ( count < 10 ) { printf(“%d\n”, count); count=count+1; } return 0; } Example -- Count to 10 (cont) Print out numbers 0 to 9 set count to 0 while ( count is less than 10 ) { output count add 1 to count }

#include /* Print out numbers 0 to 9 */ int main() { int count; count = 0; while ( count < 10 ) { printf(“%d\n”, count); count=count+1; } return 0; } Example -- Count to 10 (cont) Print out numbers 0 to 9 set count to 0 while ( count is less than 10 ) { output count add 1 to count } Format string

#include /* Print out numbers 0 to 9 */ int main() { int count; count = 0; while ( count < 10 ) { printf(“%d\n”, count); count=count+1; } return 0; } Example -- Count to 10 (cont) Print out numbers 0 to 9 set count to 0 while ( count is less than 10 ) { output count add 1 to count }

Find the sign of a number output “Enter a number” input num if (num is less than 0) then { output num “ is -’ve” } else { output num “ is +’ve” } #include /* Find the sign of a number */ int main() { float num; printf(“Enter a number: “); scanf(“%f”, &num); if ( num < 0 ) { printf(“%f is -’ve\n”, num); } else { printf(“%f is +’ve\n”, num); } return 0; } Example -- What’s your sign?

Find the sign of a number output “Enter a number” input num if (num is less than 0) then { output num “ is -’ve” } else { output num “ is +’ve” } #include /* Find the sign of a number */ int main() { float num; printf(“Enter a number: “); scanf(“%f”, &num); if ( num < 0 ) { printf(“%f is -’ve\n”, num); } else { printf(“%f is +’ve\n”, num); } return 0; } Example -- What’s your sign? (cont)

Find the sign of a number output “Enter a number” input num if (num is less than 0) then { output num “ is -’ve” } else { output num “ is +’ve” } #include /* Find the sign of a number */ int main() { float num; printf(“Enter a number: “); scanf(“%f”, &num); if ( number < 0 ) { printf(“%f is -’ve\n”, num); } else { printf(“%f is +’ve\n”, num); } return 0; } Example -- What’s your sign? (cont)

Find the sign of a number output “Enter a number” input num if (num is less than 0) then { output num “ is -’ve” } else { output num “ is +’ve” } #include /* Find the sign of a number */ int main() { float num; printf(“Enter a number: “); scanf(“%f”, &num); if ( num < 0 ) { printf(“%f is -’ve\n”, num); } else { printf(“%f is +’ve\n”, num); } return 0; } Example -- What’s your sign? (cont)

Find the sign of a number output “Enter a number” input num if (num is less than 0) then { output num “ is -’ve” } else { output num “ is +’ve” } #include /* Find the sign of a number */ int main() { float num; printf(“Enter a number: “); scanf(“%f”, &num); if ( num < 0 ) { printf(“%f is -’ve\n”, num); } else { printf(“%f is +’ve\n”, num); } return 0; } Example -- What’s your sign? (cont)

Topics History of C Structure of a C program Values and variables Expressions Function calls Comments

Values and Variables Basic Types: –Integers –Floating point numbers –Characters –Character Strings

Basic Types: int and float Integers ( int ) Floating point numbers ( float ) e-1 1e1

Basic Types: char Characters ( char ) ’a’ ’z’ ’A’ ’Z’ ’?’ ’0’ ’9’ - Special Characters: preceded by \ ’\n’ ’\t’ ’\0’ ’\’’ ’\\’ etc.

Basic Types: character string Character Strings (a string of char -s) Examples: –”Hi there!” –”Line 1\nLine 2\nLine 3” –”” –”\”\””

Topics History of C Structure of a C program Values and variables

Reading King –Chapter 1, 1.1 – 1.2 –Chapter 2, 2.1 D&D: –Chapter 2, Sections 2.1 to 2.5 Kernighan & Ritchie –Chapter 1, 1.1