By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.

Slides:



Advertisements
Similar presentations
11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
 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.
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Structure of a C program
CMT Programming Software Applications
Introduction to C Programming
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
By: Mr. Baha Hanene Chapter 4. LEARNING OUTCOMES This chapter will cover learning outcome no. 2 i.e. Use basic data-types and input / output in C programs.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Programming With C.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Week 1 Algorithmization and Programming Languages.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Introduction to Programming
CC112 Structured Programming Lecture 2 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.
CHAPTER # 2 Part 2 PROGRAMS AND DATA 1 st semster King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
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.
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
CSCE 206 Structured Programming in C
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CSC201: Computer Programming
Chapter 2 - Introduction to C Programming
Chapter 2, Part I Introduction to C Programming
Basic Elements of C++.
Revision Lecture
ICS103 Programming in C Lecture 3: Introduction to C (2)
Getting Started with C.
Introduction to C Programming Language
Chapter 2 - Introduction to C Programming
Basic Elements of C++ Chapter 2.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter # 2 Part 2 Programs And data
Introduction to Computer Programming
Chapter 2 - Introduction to C Programming
Variables in C Topics Naming Variables Declaring Variables
Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Getting Started With Coding
Presentation transcript:

By: Mr. Baha Hanene Chapter 3

Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in C programs. (L02) 2

Contents Introduction to Programming Stages & Steps of Writing Programs Preprocessor Directives Main Function Output Statement Variables in C Assignment Statements Sample Programs References 3

Programming Introduction A language which is used to instruct computer to perform different tasks according to the requirements. Every programming language has following basic things. 4  Declarations  Assignments  Control Statements  I/O (Input/output) Statements

Programming Introduction Any programming language consists of its own keywords and syntax rules that distinguishes it from other programming languages. If you want to program in a specific language, you need the compiler of this specific language. For example, C language compiler translates programs written in C language to machine language. 5

Programming Style Keep it clear & simple Keep it short Think it through in advance 6

Stages & Steps of Writing Programs 7 Specification Design Coding Testing Documentation Maintenance

Preprocessor Directives In C programming whenever you see lines that begin with a in column 1 are called preprocessor directives (commands) The #include directive allows the processor to include basic Input / Output in the program at this point. 8 #

stdio.h This header file we include in all programs where we need to use basic I/O commands e.g. printf(“”); scanf(“”); Some functions are very difficult and very long to write, these header files contains built in functions to provide us help in writing the programs. 9

void main( ) Every C program has a main function, this is where the program starts it’s execution, as this is the first function to execute in the whole c program. The reserved word “void” shows that this function will not return any value. Each C program can contain only one main function e.g. void main() 10

Function Body A left brace (curly bracket) -- { -- begins the body of every function. A corresponding right brace -- } -- ends the function body. void main() { …… } 11 BODY Main Function

printf(“”); This line is called a C statement printf(“”); is a function which is used to instruct computer to display something on computer screen All text, special symbols you will type inside printf(“”); between the double quotations i.e. “……..” will be displayed as it is on your computer screens except few commands like /t, /n, %i etc.e.g. printf(“Welcome at KIC”); Notice that the above line ends with a Semicolon ; (every C statement ends with a semicolon i.e. ;) 12

Sample Program Explanation #include void main() { printf(“Hello to programming”); printf(“\n Welcome at KIC”); printf(“\t at Fall 2010/11”); } 13 Header File used for Input / Output Main Function Necessary to start any C program Output Statement used to display on screen Function Start Function End \t \n Start New Line Give Space between text

Variables in C In computer programming, a variable is a name given to some known or unknown quantity or value, for the purpose of allowing the name to be used independently of the value it represents [Data Type][Variable Name] ; Data Types: In C programming there are more data types but we generally use the following data types. (more details in next chapter) 1. int2. float3. char 14

Variables in C Variable Name: You can give any name to the variables in c but there are few rules for writing variable names. (A-Z) The first character must be a letter Space is not allowed between names of identifiers Special symbols are not allowed in identifier names - Hyphens are not allowed in identifier names however underscores _ can be used (int, float, private etc.) The reserve words are not allowed in identifier names. 15

Variables in C Some valid identifiers / variable names hello j9 box22a get_data bin3d4 count Some reserve words (can’t be used as identifier): private else static int const float 16

Variables in C 17 velocity freda time-of-day int tax_rate x2 4x first value emp. velocity freda time_of_day INVALID tax_rate x2 x4 first_value radio4 emp RIGHT WRONG

Variables in C How & where we write variables in C programming….? We usually declare all variables inside main function for example: 18 #include void main() { int avar ; int salary ; float percentage ; } Data Type Variable Name Semi Colon (every C statement ends with a semicolon ;)

Sample Program 19 Multiple Variable Declaration Any Questions ? ??? ????? Assignment Statements

Before using variables in assignment statements you should define / declare them first e.g. int a; Assignment Statements first_number = 35; second_number = 21; sum = first_number + second_number; The first two statements assigns the values 35 and 21 to the variables first_number and second_number respecitively The next statement assigns the sum of the two values to the variable sum. 20

Sample Program 21 Header File Main Function Function Body Variable Declaration Assignment Statements Screen Output

Displaying Variable Value Do you see something different in normal printf statements and these which we have seen in the last sample program??? 22 What are these things???? %d These are called Format Specifiers used to display the value stored in the variable i.e. Inside computer memory

Sample Program Output 23

The Logical Flow 24 Source Program Compile Syntax Error OK Object Code/ Program Run Run-time Error OK Result Logical Error OK END Continue

References 25