1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University

Slides:



Advertisements
Similar presentations
Chapter 2: Basic Elements of C++
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Problem Solving & Program Design in C Sixth Edition By Jeri R. Hanly & Elliot B. Koffman 1-1.
Program Looping EE2372 Software Design I Dr. Gerardo Rosiles.
Engineering EG167C - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
TDBA66, VT-03 Lecture - Ch. 21 A complete C-program Display Fig. 2.1 and comment on different things such as Preprocessor directives Header files Identifiers.
1 CS 201 Introduction to C (1) Debzani Deb. 2 Outline Overview of C General form of a C program C Language Elements.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
The scanf Function The scanf function reads input from the standard input device into one or more variables Example: scanf(“%lf”, &miles); Reads a real.
1 CSC 1401 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 2: Overview of C Problem Solving & Program Design in C Sixth.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Basic Elements of C++ Chapter 2.
© 2012 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 2: Overview of C Problem Solving & Program Design in C Seventh.
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.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Chapter 2 Overview of C Instructor: Kun-Mao Chao ( 台大資工 趙坤茂 )
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman CPCS 202 Chapter 2 – Input/Output
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
Chapter 2 Overview of C Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
C Programming n General Information on C n Data Types n Arithmetic Operators n Relational Operators n if, if-else, for, while by Kulapan Waranyuwat.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
CP104 Introduction to Programming Overview of C Lecture 4__ 1 Assignment Statements An assignment statement is to store a value in a variable variable.
Introduction to Programming
ELE118 Introduction to Programming
CC112 Structured Programming Lecture 2 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.
Khalid Rasheed Shaikh Computer Programming Theory 1.
Overview of C. C—a high-level programming language developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories. We will discuss: –the elements of a.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
CISC105 – General Computer Science Class 2 – 6/7/2006.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
A.Abhari CPS1251 Topic 2: C Overview C Language Elements Variable Declaration and Data Types Statement Execution C Program Layout Formatting Output Interactive.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
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.
C Language Elements Preprocessor Directives # (sign for preprocessor directive commands) #include Standard header file (.h) Library.
1-1 © 2012 Pearson Addison-Wesley. All rights reserved. CC213: PROGRAMMING APPLICATIONS Dr. Manal Helal Fall 2014.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Lecture2.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Basic Elements of C++.
What's a Computer? Monitor Disk Main mouse Memory Keyboard Network
Test Review Computer Science History
Revision Lecture
ICS103 Programming in C Lecture 3: Introduction to C (2)
Lecture2.
Chapter 2 Overview of C.
Basic Elements of C++ Chapter 2.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Lecture3.
Chapter 2: Overview of C Problem Solving and Program Design in C 5th Edition by Jeri R. Hanly and Elliot B. Koffman.
Introduction to C Programming
Computer Science II CS132/601* Lecture #C-1.
Presentation transcript:

1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University Spring 2009

Overview of C Lecture 3

3 Objectives Structure of simple C programs Simple data types int, double, and char. Input/output functions printf and scanf. Preprocessor directives #include and #define Comments Assignment statement along with the basic arithmetic operators Case Study Common Errors

4 C Language Elements Preprocessor directives Main function { }

5 General Form of a C program Preprocessor directives: #include, #define Main function: int main (void) Any used variable should be declared before the usage.

6 Variable Declarations Variables: values stored in variables can changes Variables Declarations: What kind of information will be stored in each variable How that information will be represented in memory SYNTAX: int variable_list; double variable_list; char variable_list; EXAMPLES: int count,large; double x, y, z; char first_initial; char ans;

7 Data Types int Range : ~ in ANSI C double char ‘ A ’ ‘ a ’ ‘ z ’ ‘ 2 ’ ‘ 9 ’ ‘ * ’ ‘ ? ’

8 Executable Statements Program in Memory Assignment Statements Input/Output Functions C function: printf C function: scanf Arithmetic Expressions

9 Assignment Statements Memory(a) Before and (b) After Execution of a Program

10 Before and After Assignment of a variable kms = KMS_PER_MILE * miles;

11 Before and After Assignment of a variable sum = sum + item;

12 Function: printf

13 Function: scanf scanf("%lf", &miles);

14 scanf scanf("%c%c%c", &letter_1, &letter_2, &letter_3 );

15 Arithmetic Expressions Arithmetic Operators Mixed-Type Assignment Statement Expression with Multiple Operators

16 Arithmetic Operators

17 Execution of Multiple Operators Can be expressed as an Evaluation Tree. area = PI * radius * radius;

18 Step by Step Expression Evaluation

19 Evaluation Tree (1) v = (p2 - p1) / (t2 - t1);

20 Evaluation Tree (2) z - (a + b / 2) + w * -y

21 Common Programming Errors Syntax Errors Run-Time Errors Undetected Errors Logic Errors

22 Summary Structure of simple C programs Simple data types int, double, and char. Input/output functions printf and scanf. Preprocessor directives #include and #define Comments Assignment statement along with the basic arithmetic operators Case Study Common Errors