The C Programming Language

Slides:



Advertisements
Similar presentations
1 C++ Syntax and Semantics The Development Process.
Advertisements

Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
1 CS 161 Introduction to Programming and Problem Solving Chapter 9 C++ Program Components Herbert G. Mayer, PSU Status 10/20/2014.
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
Introduction to C Programming CE Lecture 1 Introduction to C.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
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.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
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.
Hello World 2 What does all that mean?.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Computer Science 101 Introduction to Programming.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
EPSII 59:006 Spring Introduction to C More Administrative Details The C Programming Language How a computer processes programs Your first C program.
Sharda University P. K. Mishra (Asst.Prof) Department of Computer Science & Technology Subject Name: Programming Using C Sub Code: CSE-106 Programming.
Computer Programming I Hour 2 - Writing Your First C Program.
Introduction to programming in the Java programming language.
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.
CC112 Structured Programming Lecture 2 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
CPS120: Introduction to Computer Science Introduction to C++
Structured Programming (4 Credits) HNDIT Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,
MAHENDRAN. Session Objectives Session Objectives  Discuss the Origin of C  Features of C  Characteristics of C  Current Uses of C  “C” Programming.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Fundamentals of Programming I Overview of Programming
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 1.2 Introduction to C++ Programming
Why don’t programmers have to program in machine code?
Programming what is C++
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Computer Science 210 Computer Organization
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Introduction to the C Language
Input and Output: I/O Finish reading chapters 1 and 2 of the text
C Programming Hardik H. Maheta.
Basic Elements of C++.
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
Chapter 1. Introduction to Computers and Programming
Introduction to C Topics Compilation Using the gcc Compiler
' C ' PROGRAMMING SRM-MCA.
Lecture2.
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.
Basic Elements of C++ Chapter 2.
Computer Science 210 Computer Organization
Introduction to the C Language
Introduction to the C Language
Hello World 2 What does all that mean?.
Creating your first C program
Programming Fundamentals Lecture #3 Overview of Computer Programming
A programming language
C programming Language
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
CPS120: Introduction to Computer Science
C Programming Language
Lexical Elements & Operators
An Overview of C.
Computer Science Department
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

The C Programming Language Hunan Institute of Science and Technology

Course Arrangement Class hours : Total : 72 hours 5rd ~ 18th week 12/9/2018 Course Arrangement Class hours : Total : 72 hours 5rd ~ 18th week Teaching : 48 hours 5rd ~ 16th week Programming : 24 hours 7th ~ 18th week 2

Examination of The Course 12/9/2018 Examination of The Course The exam contains 3 parts : Written test : 60% Homework and Programming experiments : 30% Programming test : 10% 3

Chapter 1 Overview of C PROGRAMMING IN ANSI C

Chapter 1 Overview of C Characteristics History 12/9/2018 Chapter 1 Overview of C Characteristics Structured High-level Machine Independent History UNIX C language use the way closed to the human nature language to express the order statements. These statements are easily to be memorized and be understood. The Compiler translates a C program to the machine codes composed by 0 and 1, and then let computer execute these machine codes. However, programmers don’t need to consider it. The function is the basic unit of C language. A C program performs its task by calling various functions, and it has a good control structure. C program can be executed in different computers, and you need not consider the difference between various computers. C language was developed along with UNIX. In fact, the goal of the birth of C is to program UNIX. Both UNIX and the most of the programs which run on UNIX are written in C. 5

A Simple C Program 1 – Printing a Message 12/9/2018 A Simple C Program 1 – Printing a Message The forms of the main statement: main() int main() void main() main (void) void main(void) int main(void) main() { /*---------- printing begins ----------*/ printf("I see, I remember!"); /*----------- printing ends -----------*/ } 1) Every program must have only one main function comment Every program must have only one main function! 2) The comments cannot be nested! 3) Every statement should end with “;” I see, I remember! I see, I remember! 4) C makes a distinction between uppercase and lowercase letters /*This is a C program /*output*/, 09-01-08*/ printf("I see, "); printf("I remember!"); printf("I see, \nI remember!"); printf("I see, \n"); printf("I remember!"); The comments cannot be nested in C !!! 5) newline character: “\n” 6

A Simple C Program 2 – Adding Two Numbers 12/9/2018 A Simple C Program 2 – Adding Two Numbers main() { int number; float amount; number = 100; amount = number + 75.35; printf("number=%d\n", number); printf("amount=%6.2f", amount); } All variables must be declared before they are used. number amount 100 175.35 number=100 amount=175.35 number=100 _ 7

A Simple C Program 3 – Interest Calculation 12/9/2018 A Simple C Program 3 – Interest Calculation #define PRINCIPAL 5000.00 main() { float amount, inrate=0.11; amount = PRINCIPAL; amount = amount + inrate * amount; printf("Amount = $%.2f", amount); } Amount = $5550.00 5000.00 = 5000.00+ inrate * 5000.00 ; PRINCIPAL = PRINCIPAL + inrate * PRINCIPAL ; Error … 6: Lvalue reqired in function main #define instruction is a preprocessor compiler directive and not a statement, so it should not end with a “;” 8

A Simple C Program 4 – Use of Subfunctions 12/9/2018 A Simple C Program 4 – Use of Subfunctions int mul (int x, int y) { int p; p = x * y; return(p); } main() { int a=5, b=10, c; c = mul (a, b); printf("%d * %d = %d", a, b, c); 5 * 10 = 50 mul(5, 10) 50 9

A Simple C Program 5 – Use of Math Functions 12/9/2018 A Simple C Program 5 – Use of Math Functions #include <math.h> #define PI 3.1416 main() { int angle=30; float c; c = sin((PI/180) * angle); printf("sin(%d) = %.2f", angle, c); } sin(30) = 0.50 10

Basic Structure of C Programs 12/9/2018 Basic Structure of C Programs Documentation Section Link Section Definition Section Global Declaration Section main() Function Section { Declaration part Executable part } User-defined functions function 1 …… function n 11

Programming Style C allows the free-form programming. 12/9/2018 Programming Style C allows the free-form programming. Symbolic constants are written in uppercase letters, and others, such as variables or function names, in lowercases. Each statement is placed in a line by itself. Don’t write one statement in two or more lines. Don’t write two or more statements in one line. Properly write blank line, such as between declarations and executable statements. Use comments properly. Align a pair of braces. Align the statements in the same layer. And indent those statements in lower layer. 12

12/9/2018 Executing a C Program Create the source program. (the file extension is “.c”) Compile the source program. It generates the object code file. (the file extension is “.obj”) Link the program with other program files and functions that are required by the program. It generates executable file (the file extension is “.exe”). Execute the executable file. 13

Homework Review Questions P19 12/9/2018 Homework Review Questions P19 1.1~1.4 & 1.8~1.10 (Write down in your exercise book) 1.5~1.7 (Think about them, and then check your thought through programming experiments) 1.11~1.20 (Think whether you can understand all of them) Programming Exercises 14