Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

Variables in C Amir Haider Lecturer.
C++ Basics Variables, Identifiers, Assignments, Input/Output.
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University.
Structure of a C program
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?
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
C programming Language and Data Structure For DIT Students.
C PROGRAMMING LECTURE C-language Computer Fundamentals.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
C Programming Laboratory I. Introduction to C Language /* the first program for user */ #include int a=0; int main(void) { printf(“Hello World\n”); return.
Chapter 2: Java Fundamentals
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Gator Engineering 1 Chapter 2 C Fundamentals (Continued) Copyright © 2008 W. W. Norton & Company. All rights reserved.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
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.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
C++ Lesson 1.
Variables, Identifiers, Assignments, Input/Output
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
LESSON 3 IO, Variables and Operators
Introduction to C Programming Language
مبانی کامپیوتر و برنامه سازی
CMSC 104, Section 4 Richard Chang
INTRODUCTION c is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs.
Introduction to the C Language
Introduction to the C Language
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
פרטים נוספים בסילבוס של הקורס
Introduction to Java Programming
Variables in C Topics Naming Variables Declaring Variables
Basics of ‘C’.
Chapter 1: Computer Systems
פרטים נוספים בסילבוס של הקורס
Govt. Polytechnic,Dhangar
Variables in C Topics Naming Variables Declaring Variables
Units with – James tedder
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Govt. Polytechnic,Dhangar
Variables in C Declaring , Naming, and Using Variables.
Chapter 2: Introduction to C++.
C programming Language
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Language C Language.
Building Blocks of C Programming Language
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013

3 Learning Outcomes At the end of this session, student will be able to: Define element and structure of C programming language (LO1 & LO2) T Algorithm and Programming

4 Sub Topics Introduction to C Programming: –History of C –C Standard Library –C Structure –Comments –Escape Sequences –Character –Identifier –Keywords T Algorithm and Programming

5 History of C C evolved from two previous languages, BCPL and B.BCPL was developed in 1967 by Martin Richards In 1970, Ken Thompson used B to create early versions of the UNIX operating system at Bell Laboratories C language was evolved form B by Dennis Ritchie at Bell Laboratories and was originally implemented on DEC PDP-11 computer in 1972 The publication in 1978 of Kernighan and Ritchie’s book, The C Programming Language 1983  X3J11 technical committee was created to make a standard of the language 1989  Standard was approved 1999  The standard was updated C99 is a revised standard for the C programming language T Algorithm and Programming

6 Why Using C Flexibility Close to low level machine language yet easy to understand Portability Used form micro computer to super computer A Well Known Programming Language It is used in many forms of implementations such as O/S, scientific application, business application, etc. Supported With a Large Number of Libraries T Algorithm and Programming

7 C Standard Library When programming in C, you’ll typically use the following building blocks: C Standard Library Functions Example: - : Mathematical Functions - : Input and Output - : Utility Functions - : String Functions - : Time and Date Functions Functions you create yourself Functions other people have created and made available to you T Algorithm and Programming

8 C Structure C language is a structural programming language It consists of functions There is no separation between function and procedure (if you are from Pascal language background) Each C program has one main function called main Program will be started from the first line of the main function C language is case sensitive Every statement should be ended with a semi-colon (;) T Algorithm and Programming

9 C Structure T Algorithm and Programming main() { statements; } main() { statements; return(0); } void main() { statements; } int main() { statements; return(0); }

10 C Structure However, not all C compiler is familiar with all main function format described previously No. 3 and 4 would be a general/standard main function format return(0), suggesting a normal program exit A default integer (int) data type will be given for every function as a default. No. 3 and 4 have the same meaning Example: using Turbo C 2.0 (DOS) and Microsoft Visual C++ (windows) compiler, (2), (3) and (4)  success, but (1) warning using Dev-C (windows) and gcc (linux) (1), (3), and (4)  success, but (2) warning T Algorithm and Programming

11 C Structure T Algorithm and Programming int main() { printf (“Welcome to BINUS\n”); return 0; } #include int main() { printf (“Welcome to BINUS\n”); return(0); } Using Turbo C 2.0, the code will result in error. Error Message: Function should have a function prototype #include is a directive command to tell the computer to search for printf function prototype at header file stdio.h as well

12 C Structure Directive #include generally written at the beginning of a program Coding Style (depends to the programmer) T Algorithm and Programming #include int main() { printf (“Welcome to BINUS\n”); return (0); } #include int main(){ printf (“Welcome to BINUS\n”); return (0); }

13 Comments Used for readability of the program Not accounted as a command/statement by the compiler Using /* and */ Using // at the beginning of line for one line comment Example: T Algorithm and Programming /* My First Program */ #include void main(){ printf (“Hello, BINUSIAN\n”); } // This program will simply print out a message

14 Escape Sequences \abell, alert, system beep \bback space \thorizontal tab \nnew line, line feed \vvertical tab \rcarriage return \’single quote \”double quote \\backslash \xddhexadecimal notation \dddoctal notation T Algorithm and Programming

15 Character C program is written using ASCII character subset: -Capital letters A…Z -Lower Case a…z -Digit 0…9 -Special characters ‘!’, ‘&’, ‘+’, ‘\’, ‘_’, etc. ASCII American Standards Committee for Information Interchange T Algorithm and Programming

16 Identifier The naming mechanism for various element in a program such as: variable, function, constant, etc. Started with a letter or underscore_ It is case sensitive Maximum length is vary for every compiler Example: Turbo 2.0 (DOS), max 32 characters Never use reserved word/keyword (such as: for, while, if, main) Example: name, x1, _total, cubic() wrong: 1time, int T Algorithm and Programming

17 Keywords Keywords/reserved words are words that have special meaning to the C compiler. Example: Keywords added in C99 _Bool _Complex _Imaginary inline restrict T Algorithm and Programming Keywords auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while

18 Keywords Some compilers will highlight keywords with distinct color, as seen from the figure below T Algorithm and Programming Keywords in Visual C++ use blue color

Sample Code Bina Nusantara University 19 Math.h Sample :

Bina Nusantara University 20 Sample Code Stdio.h & stdlib.h Sample :

Bina Nusantara University 21 Sample Code String.h Sample :

Bina Nusantara University 22 Sample Code Time.h Sample :

Exercise State whether each of the following statements is TRUE or FALSE. If it is FALSE, explain why. 1.Every C program begins execution at main function 2.Comments cause the computer to print the text enclosed between /* and */ on the screen when the program is executed 3.All variables must be defined before used 4.All variables must be given a type when they’re defined 5.C considers number and Number to be identical Bina Nusantara University 23

24 References Paul J. Dietel,Harvey M. Deitel, C : how to program. PEAPH. New Jersey. ISBN: Chapter 1 & 2 Writing Your First C Program: Data Types and Names in C: T Algorithm and Programming

25 END T Algorithm and Programming