Instructor. Mehmet Zeki COSKUN Assistant Professor at the Geodesy & Photogrammetry, Civil Eng. (212)

Similar documents
Chapter 1 Introduction to Computers and C++ Programming

0 Introduction: Computer systems and program development

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

Chapter 1 & 2 Introduction to C Language

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

Fundamentals of Programming. Lecture 1: Introduction to C Programming

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Introduction to Computers, the Internet and the Web Pearson Education, Inc. All rights reserved.

CS Prof J.P.Morrison

by Pearson Education, Inc. All Rights Reserved.

Chapter 2, Part I Introduction to C Programming

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

EL2310 Scientific Programming

Fundamentals of Programming Session 4

C++ Programming Language Lecture 1 Introduction

Basic Computer Programming for ISNE. Santi Phithakkitnukoon ผศ.ดร.ส นต พ ท กษ ก จน ก ร

EL2310 Scientific Programming

Introduction to C Programming

Fundamentals of Programming. Lecture 3: Introduction to C Programming

C: How to Program. Week /Mar/05

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

Notes By: Shailesh Bdr. Pandey, TA, Computer Engineering Department, Nepal Engineering College

Chapter 2 - Introduction to C Programming

Preview from Notesale.co.uk Page 6 of 52

Chapter 1 Introduction to Computers and C++ Programming

These all slide pages are selected from C How to Program, 5/e and 7/e Asst.Prof.Dr.Mahmut YALCIN

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #03 The Programming Cycle

IS 0020 Program Design and Software Tools

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

introduction week 1 Ritsumeikan University College of Information Science and Engineering Ian Piumarta 1 / 20 imperative programming about the course

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Programming I Laboratory - lesson 01

BLM2031 Structured Programming. Zeyneb KURT

Programming for Engineers Introduction to C

Introduction to Basis and Practice in Programming

1 EEE1008 C Programming

LECTURE/ STUDY NOTES ON C

(0) introduction to the course. how to learn a programming language. (0) course structure

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

SEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010

Tutorial No. 2 - Solution (Overview of C)

Structured Languages. Rahul Deodhar

COMP1917: Computing 1 1. Introduction

IS12 - Introduction to Programming. Lecture 7: Introduction to C

Unit. Programming Fundamentals. School of Science and Technology INTRODUCTION

EC 413 Computer Organization

1.1 Introduction to C Language. Department of CSE

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

C Language, Token, Keywords, Constant, variable

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

COMP1917: Computing 1 1. Introduction

Work relative to other classes

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

Data types, variables, constants

Course Outline Introduction to C-Programming

1. Introduction. Course Web Site. COMP1917: Computing 1. Textbook. Occupational Health and Safety (OHS)

PROGRAMMAZIONE I A.A. 2017/2018

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Introduction to Computing Lecture 01: Introduction to C

last time in cs recitations. computer commands. today s topics.

Introduction to C Language

A Fast Review of C Essentials Part I

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Problem Solving With C++ Ninth Edition

EL2310 Scientific Programming

Introduction to Programming

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Programming and Data Structure

Welcome (back) to CS1007!

Some Computer Preliminaries

CSI33 Data Structures

printf( Please enter another number: ); scanf( %d, &num2);

6.096 Introduction to C++ January (IAP) 2009

Fundamental of Programming (C)

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

Lab # 02. Basic Elements of C++ _ Part1

Chapter 1 Overview of Programming and Problem Solving By C.K. Liang

Chapter 1 INTRODUCTION

Chapter 1 Introduction to Computers and C++ Programming

Introduction to C++ CS 1: Problem Solving & Program Design Using C++

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

1 The Catholic University of Eastern Africa P.o Box , Nairobi Kenya Edward Kioko 2013

C Introduction. Comparison w/ Java, Memory Model, and Pointers

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Computer Programming

Spring 2018 NENG 202 Introduction to Computer Programming

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

CS201 - Introduction to Programming FAQs By

Introduction to Computing using C++ Biomedical applications WELCOME TO CIS 1.5. Introduction to the course. Course structure

Fundamentals of Programming (C)

Program Organization and Comments

CS150 Introduction to Computer Science 1. What is CS150? Who Are We? CS150 is a programming course You will learn

IT 374 C# and Applications/ IT695 C# Data Structures

Course Outline. Introduction to java

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva

Transcription:

Instructor Mehmet Zeki COSKUN Assistant Professor at the Geodesy & Photogrammetry, Civil Eng. (212) 285-6573 coskunmeh@itu.edu.tr http://atlas.cc.itu.edu.tr/~coskun

Address Consultation of Students: Monday 10:00 12:00

Course WEB site Lecture Notes http://atlas.cc.itu.edu.tr/~coskun Compiler http://atlas.cc.itu.edu.tr/~coskun Samples http://www.be.itu.edu.tr/kaynak/c

Working Environment Windows 95, 98, 2000, NT, XP Linux Browser, etc. Compiler Editor

Lecture Notes What you will be reading on this screen will always be available at the Web site Taking notes: it s up to you to decide!

The following slides are compiled from free version of the books: Text Books: Sams Teach Yourself C in 21 Days (Sams teach Yourself) By Peter Aitken Sams Teach Yourself C in 24 hours (Published by Sams) By Tony Zhang... The Electronic Versions of the books: http://server11.hypermart.net/davidbook901/data/c/c1f8c0d9.htm http://www.informit.com/itlibrary http://www.free-book.co.uk/computers-internet/programming/c/ http://aelinik.free.fr/c/

Schedule First two hours for Lecture Last two hours Lab.

Requirements [4 or more HOMEWORKS = 20% ] Pick it up from to Web site; turn it in by Quizes [2 QUIZES = 15%] at any time Midterm [1Midterm = 25%] will inform Final [40%]

BIL104E: Introduction to Scientific and Engineering Computing Lecture 1 Inroduction Getting Started Writing your First C Program

Computing systems Central Processing Unit (CPU) [ has registers] Memory (these days, RAM, Random Access Memory] Input/Output units: video card+monitor, keyboard, etc. Storage units [disks]

Computer memory organization Units of measure Basic unit: bit 8 bits = 1 byte 1024 bytes = 1 Kbyte or 1 K 1024 K = 1 Megabyte or 1 M CPU registers, RAM, ROM [Read-Only Memory] n bytes = 1 word (n=4, 8, etc.) 1 word = 32 bits, or 64 bits, etc.

Computer memory organization Associated with each word or byte is an address As far as the computer is concerned, instructions are data

Languages Three types of programming languages 1. Machine languages 1100000100 1000101011 1110101010 2. Assembly languages elementary computer operations LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

Languages 3. High-level languages Codes similar to everyday English Use mathematical notations (translated via compilers) grosspay = basepay + overtimepay

How a code runs

A Brief History of the C Language C was created by Dennis Ritchie at the Bell Telephone Laboratories in 1972. The language wasn't created for the fun of it, but for a specific purpose: to design the UNIX operating system (which is used on many computers). From the beginning, C was intended to be useful to allow busy programmers to get things done.

A Brief History of the C Language Now, what about the name? The C language is so named because its predecessor was called B. The B language was developed by Ken Thompson of Bell Labs. You should be able to guess why it was called B.

Programmers everywhere began using it to write all sorts of programs. Soon, however, different organizations began utilizing their own versions of C, and subtle differences between implementations started to cause programmers hackaches. In response to this problem, the American National Standards Institute (ANSI) formed a committee in 1983 to establish a standard definition of C, which became known as ANSI Standard C. With few exceptions, every modern C compiler has the ability to adhehere to this standard.

Why Use C? powerful and flexible. a popular language a portable language a language of few words, containing only a handful of terms modular

What about C++? You might have heard about C++ and the programming technique called object-oriented programming. Perhaps you're wondering what the differences are between C and C++ and whether C++ is a superset of C, which means that C++ contains everything C does, plus new additions for objectoriented programming.

Preparing to Program Determine the objective(s) of the program. Determine the methods you want to use in writing the program. Create the program to solve the problem. Run the program to see the results.

The Program Development Cycle Step 1 Use an editor for write your source code. By tradition, C source code files have the extension *.C (for example, MYPROG.C, DATABASE.C, and so on). Step 2 Compile the program using a compiler. If the compiler doesn't find and errors in the program, it produces an object file. The compiler produces object files with an.obj extension and the save name as the source code file (for example, MYPROG.C compiles to MYPPOG.OBJ). If the compiler finds errors, it reports them. You must return to step 1 to make corrections in your source code. Step 3 Link the program using a linker. If no errors occur, the linked produces an executable program located in a disk file with an.exe extensionand the same name as the object file (for example, MYPROG.OBJ is linked to create MYPROG.EXE). Step 4 Execute the program. You should test to determine whetherit functions properly. If not, start again with step 1 and make modifications and additions to your source code.

The C Standard Library C programs consist of pieces/modules called functions A programmer can create his/her own functions Advantage: the programmer knows exactly how it works Disadvantage: time consuming Programmers will often use the C library functions Use these as building blocks Avoid re-inventing the wheel If a premade function exists, generally best to use it rather than write your own Library functions carefully written, efficient, and portable

Interface of C Editor Compile to check the error(s). Lint it to run and see the result(s).

Interface of C Editor Click to make a new file. Use to load your existing programs. Use to save your programs. DO IT before you COMPILE and LINK. Compile to check the error(s). Link to run and see the result(s).

Interface of C Editor Check this option before you start.

Examples of C programs: Our first program 1 2 /* A first program in C */ 3 #include <stdio.h> 4 5 int main() 6 { 7 printf( "Welcome to C!\n" ); 8 9 return 0; 10} Output for the program is: Welcome to C!

1 2 /* A first program in C */ 3 #include <stdio.h> 4 5 int main() 6 { 7 printf( "Welcome to C!\n" ); 8 9 return 0; 10} Line 1: a blank line. Compiler does nothing... Line 1 is ignored by computer.

1 2 /* A first program in C */ 3 #include <stdio.h> 4 5 int main() 6 { 7 printf( "Welcome to C!\n" ); 8 9 return 0; 10} Line 2: Text surrounded by /* and */ is ignored by computer. Used to describe program

1 2 /* A first program in C */ 3 #include <stdio.h> 4 5 int main() 6 { 7 printf( "Welcome to C!\n" ); 8 9 return 0; 10} Line 3: A header file. Preprocessor directive. Tells computer to load contents of a certain file.

1 2 /* A first program in C */ 3 #include <stdio.h> 4 5 int main() 6 { 7 printf( "Welcome to C!\n" ); 8 9 return 0; 10} Line 3: C programs contain one or more functions, exactly one of which must be main. Parenthesis used to indicate a function. int means that main "returns" an integer value

1 2 /* A first program in C */ 3 #include <stdio.h> 4 5 int main() 6 { 7 printf( "Welcome to C!\n" ); 8 9 return 0; 10} Line 6: Braces ({ and }) indicate a block. The bodies of all functions must be contained in braces. { means block (main program body) starts.

1 2 /* A first program in C */ 3 #include <stdio.h> 4 5 int main() 6 { 7 printf( "Welcome to C!\n" ); 8 9 return 0; 10} Line 7: Instructs computer to perform an action. Specifically, prints the string of characters within quotes ( ). All statements must end with a semicolon (;). Escape character (\): Indicates that printf should do something out of the ordinary... \n is the newline character.

1 2 /* A first program in C */ 3 #include <stdio.h> 4 5 int main() 6 { 7 printf( "Welcome to C!\n" ); 8 9 return 0; 10} Line 9: A way to exit a function.return0, in this case, means that the program terminated normally.

1 2 /* A first program in C */ 3 #include <stdio.h> 4 5 int main() 6 { 7 printf( "Welcome to C!\n" ); 8 9 return 0; 10} Line 9: right brace { indicates end main of has reached.

Examples of C programs: Our second program (terminating the program with exit() function) 1 2 /* A first program in C */ 3 #include <stdio.h> 4 5 main() 6 { 7 printf( "Welcome to C!\n" ); 8 9 exit(0); 10} Output for the program is: Welcome to C!

Examples of C programs: Our second program #include <stdio.h> #include <math.h> main ( ){ /* note that we did not use int */ float x=125; double y; y = pow(x,3); /* returns 125 cubed */ printf( Hello World\n ); exit(0); }

() shows a main or a function program execution begins at main() keywords are written in lower-case C is case sensitive, use lower-case and try not to capitalise variable names statements are terminated with a semi-colon ; text strings are enclosed in double quotes ( ) \n means position the cursor on the beginning of the next line printf() can be used to display text to the screen the curly braces {} define the beginning and end of a program block

General Notes About C Program clarity Programs that are convoluted are difficult to read, understand, and modify C is a portable language Programs can run on many different computers However, portability is an elusive goal We will do a careful walkthrough of C Some details and subtleties are not covered If you need additional technical details Read the C standard document Read the book by Kernigan and Ritchie