Computer Science Department

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

CSE 105 Structured Programming Language (C)
0 - 0.
Computer Science Department Introduction To Computers and Programming Knowledge: Understand the concepts of computer, hardware, software and programming.
Computer Science Department FTSM Algorithm Knowledge: Understand algorithm representation using flowchart and pseudocode Skill: Map problem to solution.
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Module 6: Introduction to C Language ITEI102 Introduction to Programming Structure of C++ Program - Programming Terminologies - Microsoft Visual Studio.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Senem Kumova Metin // FALL CS115 Introduction to Programming Inst. Senem Kumova Metin Textbook : A Book on C, A. Kelly.
Control Structure: Loop (Part 1) Knowledge: Understand the various concepts of loop control structure Skill: Be able to develop a program involving loop.
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
BBS Yapısal Programlama (Structured Programming)
CS115 Introduction to Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to C Programming CE Lecture 1 Introduction to C.
Three types of computer languages
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.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
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.
Chapter 1 Introduction to Computers In this chapter we describe the major components of a computer system and explain how information is represented in.
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.
Creating your first C++ program
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!
C Language: Introduction
C programming language was developed in the seventies by a group of at the Bell Telephone lab. The C language was the outline of two earlier languages.
CMSC 1041 Introduction to C Creating your first C program.
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
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.
Introduction. Natural Languages are languages of the Humans These Languages tend to be ambiguous A sentence in natural may not have just one meaning I.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
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.
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.
Computer Science 210 Computer Organization
Introduction to C Language
C Programming Hardik H. Maheta.
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
Getting Started with C.
Introduction to C Topics Compilation Using the gcc Compiler
' C ' PROGRAMMING SRM-MCA.
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.
Computer Science 210 Computer Organization
The C Programming Language
Govt. Polytechnic,Dhangar
Creating your first C program
Programming Fundamentals Lecture #3 Overview of Computer Programming
C programming Language
C Programming Language
C – Programming Language
Introduction to C Programming
Computer Science Department
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