S CCS 200: I NTRODUCTION AND G ETTING S TART IN C P ROGRAMMING Lect. Napat Amphaiphan.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Lecture 2 Introduction to C Programming
Introduction to C Programming
Outline 2.1 Introduction 2.2 Basics of C Programs
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
CMT Programming Software Applications
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
Introduction to C Programming
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Chapter 2 Getting Started in C Programming
A First Book of ANSI C Fourth Edition
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
Input, Output, and Processing
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
CNG 140 C Programming Prof. Muslim Bozyiğit Dr. Ghalib A. Shah Department of Computer Engineering Mıddle East Technical University, NCC Spring
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Lesson 6 Getting Started in C Programming Hu Junfeng 2007/10/10.
Chapter 2 Variables.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
S CCS 200: I NTERACTIVE I NPUT Lect. Napat Amphaiphan.
IT CS 200: C ONDITION Lect. Napat Amphaiphan. T HE ABILITY TO CONTROL THE FLOW OF YOUR PROGRAM, LETTING IT MAKE DECISIONS ON WHAT CODE TO EXECUTE 2.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CISC105 – General Computer Science Class 2 – 6/7/2006.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
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.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
CSCE 206 Structured Programming in C
Chapter 2 Variables.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chapter 2 - Introduction to C Programming
Chapter 2: Problem Solving Using C++
Revision Lecture
Chapter 2 - Introduction to C Programming
C++ for Engineers and Scientists Second Edition
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
CS111 Computer Programming
Chapter 2 - Introduction to C Programming
Chapter 2: Introduction to C++.
Chapter 2 - Introduction to C Programming
Chapter 2 Variables.
Lexical Elements & Operators
Introduction to C Programming
Presentation transcript:

S CCS 200: I NTRODUCTION AND G ETTING S TART IN C P ROGRAMMING Lect. Napat Amphaiphan

Overview (Midterm) Midterm Examination 30 % Data Type, Declaration, Display Interactive Input SelectionRepetition Analyze Problem Solving Problem Solving int float double char printf() int float double char printf() scanf() if…else switch…case if…else switch…case while statement for statement do-while statement while statement for statement do-while statement

Intro. C Programming 1 The Syntax 2 C Editor Tool 3 Today’s Overview 3

Algorithms A procedure for solving a problem in terms of the actions to be executed and the order. Algorithm can be written in 2 different ways Pseudo-code – English-like steps that describes the solution Flowcharts – Picture with specific blocks detailing out the logical flow of the solution Problem solving Understand problem statement and analysis Develop a high-level algorithm Detail out a low-level algorithm

Pseudo-Code An artificial and informal language that helps programmers develop algorithms. Pseudo code is a "text-based" detail (algorithmic) design tool.

Flow Chart A formalized graphic representation of a logic sequence, work or manufacturing process, organization chart, or similar formalized structure. Simple geometric symbols and arrows to define relationships.

Flowchart Symbols

A First Book of ANSI C, Fourth Edition 8 Flowchart Symbols (Full)

Programming Languages

A programming language is a way for humans to write instruction code for computers. Computer communicate in binary that is ones and zeros. An example would look like this...

Programming Languages This is very hard to read and under stand so we write code that looks more like human words and would look like this...

Program Translation

What is C ? C is a programming language originally developed for developing the Unix operating system (by Dennis Ritchie).Dennis Ritchie The pure programming language with no additional concept. 13

The first C Program 14

Functions

The main() Function Sometimes referred to as a driver function

C Libraries - #include …

C Libraries - #include … (cont.) Library fileFunctions #include Standard I/O functions – printf, scanf, getc, fopen, fclose #include Traditional file operations – lock, create, filelength, read, write #include Arithmetic – abs, floor, pow, sqrt Logarithmic – log, exp, Trignometric – sin, tan, cos, atan Floating point – fabs, fmod #include String operations – strcpy, strcat, strcmp, strlen, strrev, strlwr, strupr Without including these libraries, you cannot write C programs that need to use these standard function. Check your reference for details on the C libraries, their functions and how they can be used.

Blocks & Lines Each line of code end with ; (Only Instruction) Blocks are things that start with { and end with }. 20

Line Example 21

Block Example 22

The printf( ) Function Function arguments printf("Hello there world!");

Type of Functions 1. Standard-Library Function (built-in function): Already store in C library, a programmer can instantly use it. 2. Write by Programmer: A function created by individual programmer. 24

Explaining your Code - Comment Programmers can forgot their own code. Use them to explain sections of code To create a comment in C, you surround the text with /* and then */ or using // 25

E XPANDING THE CONCEPT OF C 26

Displaying Numerical Values Function arguments Arguments are separated with commas printf("The total of 6 and 15 is %d", ); conversion control sequence

Displaying Numerical Values (cont.) Example printf("The average of 5,10 and 11 is %f",( )/3); printf("The average of 5,10 and 11 is %f", avg); printf(" %d \n %f \n %c ", 10, 10.11, ‘a’);

Arithmetic Operations Arithmetic operators: operators used for arithmetic operations: – Addition + – Subtraction - – Multiplication * – Division / – Modulus Division % – minus sign (-) used in front of a single numerical operand negates the number

Operator Precedence

Operator Precedence (cont.) Find the result of / Find the result of * 7 % 2 * % 2 * * ***Suggestion: Use () to ensure your result. ***

Using Variables // Version 4 What will happen (Variable Concept) /* int main() { int sum = 5+6+7; int multi = 10*20; int total = sum+multi; printf("%d", total); getch(); return 0; } */ 32 Declaration

Data Types Data type: define how the compiler identifies variables. Four basic data types used in C – Integer (int) – Floating point (float) – Double precision (double) – Character (char)

Data Types: Integer are any positive or negative number without a decimal point may be signed (+ or -) or unsigned no commas, decimal points, or special symbols Valid integer constants Invalid integer constants $ , ,243,892 1,

Data Types: Character Characters are letters of the alphabet (uppercase & lowercase) char Data Type is used to store individual characters. Include the letters of the alphabet (both uppercase and lowercase), the ten digits 0-9, and special symbols such as +,&,! Examples of valid character constants ‘A’ ‘$’ ‘b’ ‘7’ ‘y’ ‘!’ ‘M’ ‘q’ enclosed by single quotes (‘ ’)

ASCII Codes.

Data Types: Character

Escape Sequences

Data Types: Floating Point & Double Precision umbers are any signed or unsigned numbers having a decimal point no special symbols Valid floating point and double precision constants Invalid floating point and double precision constants 5, ,459 $10.29 Floating Point VS Double Precision Numbers

Displaying Numerical Values (cont.) Example printf("The average of 5,10 and 11 is %f",( )/3); printf("The average of 5,10 and 11 is %f", avg); printf(" %d \n %f \n %c ", 10, 10.11, ‘a’);

Variables and Declarations Variables are names given by programmers Variable names are case sensitive Rules of variable names – begin with letter or underscore (_) and may contain only letters, underscores, or digits – cannot contain any blanks, special symbols – use capital letters to separate names consisting of multiple words – cannot be a keyword – no more than 31 characters

Variables and Declarations (cont.)  general form function name( ) { declaration statements; other statements; }  simplest form dataType variableName;  Example void main() { int X,Y; float HOLA; char MyChar, mychar; other statements; }

Initialization and Assign value When a declaration statement provides an initial value, the variable is said to be initialized – int x = 10; – float y = 1.2; Assign value: right hand side to left hand side – int x; – x = 10; – x = 5+10;

Common Programming Errors Omitting the parentheses after main main  main( ) Omitting or incorrectly typing the opening brace { that signifies the start of a function body Omitting or incorrectly typing the closing brace } that signifies the end of a function Misspelling the name of a function print( )  printf( )

Common Programming Errors (cont.) Forgetting to close the message to printf( ) with a double quote (“ ”) symbol Omitting the semicolon (;) at the end of each statement Forgetting the \n to indicate a new line

? || // 46

Program: Turbo C/DevC++/Etc. 47

DevC++ Demonstration 48

Y OUR T URN 49