Bài giảng Lập trình C - Session 1: Basic of C

Differentiate between Command, Program and Software

Explain the beginning of C

Explain when and why is C used

Discuss the C program structure

Discuss algorithms

Draw flowcharts

List the symbols used in flowcharts

 

ppt26 trang | Chuyên mục: C/C++ | Chia sẻ: dkS00TYs | Lượt xem: 1825 | Lượt tải: 1download
Tóm tắt nội dung Bài giảng Lập trình C - Session 1: Basic of C, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
Basics of C Session 1 Objectives Differentiate between Command, Program and Software Explain the beginning of C Explain when and why is C used Discuss the C program structure Discuss algorithms Draw flowcharts List the symbols used in flowcharts Software, Program and Command The Beginning of C C – Dennis Ritchie B – Ken Thompson BPCL – Martin Richards Application Areas Of C C was initially used for systems programming A system program forms a portion of the operating  system of the computer or its support utilities Operating Systems, Interpreters, Editors, Assembly  programs are usually called system programs The UNIX operating system was developed using C There are C compilers available for almost all types of PC’s Middle Level Language High Level Language Assembly Language C Structured Language C allows compartmentalization of code and data It refers to the ability to section  off and hide all information and  instructions, necessary to  perform a specific task, from the  rest of the program Code can be compartmentalized in C by using functions or code blocks. About C C has 32 keywords These keywords combined with a formal syntax form a C programming language Rules to be followed for all programs written in C: All keywords are lowercased C is case sensitive, do while is different from DO WHILE Keywords cannot be used as a variable or function name main() { /* This is a sample Program*/ int i,j; i=100; j=200; : } The C Program Structure-1 The C Program Structure-2 The C Program Structure-3 The C Program Structure-4 The C Library All C compilers come with a standard library of functions A function written by a programmer can be placed in the library and used when required Some compilers allow functions to  be added in the standard library Some compilers require a separate library to be created Compiling & Running A Program The Programming Approach to Solving Problems Go to thebasement Algorithm is a set of steps that are performed to solve a problem. The example below describes an algorithm These are the steps followed when a student wants to go to the cafeteria from the classroom Solving a Problem In order to solve a problem Understand the problem clearly Gather the relevant information Process the information Arrive at the solution Pseudocode It is not actual code. A method of algorithm - writing which uses a standard set of words which makes it resemble code Each pseudocode starts with a BEGIN To show some value , the word DISPLAY is used The pseudocode finishes with an END BEGIN DISPLAY ‘Hello World !’ END Flowcharts It is a graphical representation of an algorithm START DISPLAY ‘Hello World !’ STOP The Flowchart Symbol Flowchart to add two numbers The IF Construct BEGIN INPUT num r = num MOD 2 IF r=0 Display “Number is even” END IF END Yes No The IF-ELSE Construct BEGIN INPUT num r=num MOD 2 IF r=0 DISPLAY “Even Number” ELSE DISPLAY “Odd Number” END IF END Multiple criteria using AND/OR BEGIN INPUT yearsWithUs INPUT bizDone IF yearsWithUs >= 10 AND bizDone >=5000000 	DISPLAY “Classified as an MVS” ELSE	 	DISPLAY “A little more effort required!” END IF END Nested IFs-1 BEGIN INPUT yearsWithUs INPUT bizDone IF yearsWithUs >= 10 IF bizDone >=5000000 	DISPLAY “Classified as an MVS” 	 ELSE 	DISPLAY “A little more effort required!” END IF ELSE	 	DISPLAY “A little more effort required!” END IF END Nested IFs-2 INPUT YearsWithUs START INPUT bizDone YearsWithUs >= 10 bizDone > 5000000 DISPLAY “A Little more effort required” STOP NO YES NO YES DISPLAY “A Little more effort required” DISPLAY “Classified as an MVS” Loops BEGIN cnt=0 WHILE (cnt < 1000) DO 	DISPLAY “Scooby” 	cnt=cnt+1 END DO END Yes No 

File đính kèm:

  • pptBài giảng Lập trình C - Session 1 Basic of C.ppt
Tài liệu liên quan