Computer Science Department

Slides:



Advertisements
Similar presentations
Computer Science Department
Advertisements

Introduction to C Programming CE Lecture 1 Introduction to C.
Three types of computer languages
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
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.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
C programming Language and Data Structure For DIT Students.
CSE : Programming in C Instructor: Lei Wang Office: Dreese Lab 474 Office Hour: Friday.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
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.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
Programming Design Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Basics of “C” Programming
COMPSCI 174- Introduction to C++ Class hour Section 01: MWF 9:55am – 10:45am. Hyer Hall 210.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
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.
CMSC 1041 Introduction to C Creating your first C program.
Introduction to C Programming Language. History of C  C was evolved by Dennis Ritchie at AT&T Bell Laboratories in early of 1970s  Successor of: ALGOL.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
BASIC C PROGRAMMING LANGUAGE TUTORIAL infobizzs.com.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
INTRODUCING C PROGRAMMING LANGUANGE CHAPTER 2. Lecture outline History Why C Preparing to Program in C.
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
CSE-102: PROGRAMMING FUNDAMENTALS LECTURE 3: BASICS OF C Course Instructor: Syed Monowar Hossain 1.
Introduction to C Topics Compilation Using the gcc Compiler
UMBC CMSC 104 – Section 01, Fall 2016
Computer Science 210 Computer Organization
CSC201: Computer Programming
Introduction to C Language
CS-103 COMPUTER PROGRAMMING
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
Intro to Programming Week # 1 Hardware / Software Lecture # 2
Computer Engineering 1nd Semester
Overview of C.
Introduction to C Topics Compilation Using the gcc Compiler
Getting Started with C.
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming Language
Choice of 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.
Visit for more Learning Resources
Computer Science 210 Computer Organization
Computer Science Department
The C Programming Language
Govt. Polytechnic,Dhangar
Creating your first C program
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.
Programming Fundamentals Lecture #3 Overview of Computer Programming
2008/09/29: Lecture 7 CMSC 104, Section 0101 John Y. Park
C programming Language
Introduction to Computer Programming
C Programming Language
The C Language: Intro.
C – Programming Language
Introduction to C Topics Compilation Using the gcc Compiler
Course Outcomes of Programming In C (PIC) (17212, C203):
Introduction to C Programming
Presentation transcript:

Computer Science Department Introduction to C Knowledge: Understand the complete structure of C programs in Linux environment Skill: Edit, compile and execute C programs FTSM Computer Science Department

Introduction Can also be used at lower-level C is a High-level Language Introduction This flexibility allows it to be used for SYSTEM PROGRAMMING (eg. Operating systems like UNIX and WINDOWS) C has small instruction set, though the actual implementations include extensive library functions /* Task: This program calculates BMI */ #include <stdio.h> #define WEIGHT 60.0 #define HEIGHT 1.53 void main(void) { float bmi; bmi = WEIGHT / (HEIGHT * HEIGHT); if (bmi > 25.0) printf(“\nYour BMI is %.2f. Need to lose weight! \n”, bmi); } “myfunction.h” Finally, C programs are highly portable. They can be executed on different platforms without having to be recompiled (or with little modification) Resembles Algebraic Expression C encourages users to write additional library functions of their own APPLICATION PROGRAMMING (Billing System, Sistem Semut ? ) Augmented by certain English keywords eg. if , else, while TK1913-C Programming 2

C Development Environment There are 6 phases involved: Edit Preprocess Compile Link Load Execute TK1913-C Programming 3

Editing C Program in Linux Use vi editor $vi program_name.c Use pico editor $pico program_name.c Use emacs editor $emacs program_name.c This is only an example of program name. You can give any name that you like. Example: $pico myprogram.c TK1913-C Programming 4

Compiling C Program in Linux To compile C GNU: $gcc program_name.c An error message will be displayed if there is any syntax error Needs to be rectified until there is no more errors If succeeded, the output will be generated into the execution file, namely a.out To display the output on the screen: $a.out Example: $gcc myprogram.c $a.out TK1913-C Programming 5

Compiling C Program in Linux Another method to compile C GNU: $gcc –o file_name program_name.c An error message will be displayed if there is any syntax error Needs to be rectified until there is no more errors If succeeded, the output will be generated into the execution file, namely file_name To display the output on the screen: $file_name This is only an example of execution file name. You can give any name that you like. Example: $gcc output myprogram.c $output TK1913-C Programming 6

Don’t Worry…Be Happy… Got confused?? Don’t worry, you’ll acquire this skill during the lab session. Ensure you know your lab group and schedule…good luck! TK1913-C Programming 7

History of C Language C was originated from 2 programming languages, namely BCPL and B BCPL was developed by Martin Richards in year 1967. It was intended as a language to develop operating systems and compilers B was developed by Ken Thompson in year 1970s. It was used to develop UNIX operating system at Bell Laboratories C was developed by Dennis Ritchie in year 1972. It replaced B as the language to develop UNIX operating system at Bell Laboratories TK1913-C Programming 8

C Program Structure Preprocessor Instruction Global Declaration void main (void) { } Local Declaration Statement TK1913-C Programming 9

Example of C Program Main function program statement Preprocessor instruction #include <stdio.h> void main(void) { printf(“Welcome to UKM!”); } statement TK1913-C Programming 10

Preprocess Instruction 2 types of preprocess instruction that are normally used: #include #define #include is used to include certain files into the program. Those files need to be included because they contain the necessary information for compilation (e.g. stdio.h file contains information about printf function) TK1913-C Programming 11

Preprocess Instruction #define is used to declare macro constants Example: #include <stdio.h> #define PI 3.141593 void main(void) { float luas; luas = 3.141593 * 7 * 7; printf(“Luas %.2f:”, luas); } After preprocess Macro constant Before preprocess Example: #include <stdio.h> #define PI 3.141593 void main(void) { float luas; luas = PI * 7 * 7; printf(“Luas %.2f:”, luas); } TK1913-C Programming 12

Main Function Every C program must have a main function, called main() The execution of C program starts from main() function TK1913-C Programming 13

printf(“Welcome to UKM”); Statement ‘Sentence-like’ action steps that are written in the body of the function In C, all statements must be ended with ; symbol Example: A statement to display a string of characters on the screen by using printf() function printf(“Welcome to UKM”); Output: Welcome to UKM TK1913-C Programming 14

Comment You could include comments in your program to ease understanding Comments will be ignored during compilation A block of comment is labeled with /* (start) and */ (end)  compiler will ignore any text written after /* symbol till */ symbol is found Nested comments (comment within comment) are not allowed, for example: /* my comment /* subcomment*/ my comment continues */ TK1913-C Programming 15

Example of C Program /* This program is to print Welcome to Fakulti Teknologi dan Sains Maklumat */ #include <stdio.h> void main() { printf(“Welcome to\n”); printf(“Fakulti Teknologi dan“); printf(“Sains Maklumat\n”); } TK1913-C Programming 16

Example of C Program What will the output be? Welcome to Fakulti Teknologi dan Sains Maklumat TK1913-C Programming 17

End of Lecture 3 Yes !! That’s all? What’s next??? VARIABLES AND CONSTANTS on the way … TK1913-C Programming 18