© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.

Slides:



Advertisements
Similar presentations
Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
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.
Introduction to C Programming
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
CMT Programming Software Applications
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Assignment Operators =, +=, *= A += B means (A+B) --->A or A = (A+B) Similarly true for -=, *=, /=, and %=. The basic rule is from right to left. Never.
Introduction to Computers and Programming - Class 2 1 Introduction to Computers and Programming Class 2 Introduction to C Professor Avi Rosenfeld.
Data types and variables
Expressions An expression is a sequence of operands and operators that reduces to a single value expression operator operand An operator is a language-specific.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Chapter 2 Data Types, Declarations, and Displays
Introduction to C Programming
1 MATERI PENDUKUNG OPERATOR Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
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.
Programming Variables. Named area in the computer memory, intended to contain values of a certain kind (integers, real numbers, characters etc.) They.
Chapter 01: Introduction to Computer Programming
Objectives You should be able to describe: Data Types
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
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.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
© 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.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
Week 1 Algorithmization and Programming Languages.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
Variables Symbol representing a place to store information
© 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.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
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.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
© Copyright by Deitel 1 Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 2 Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
ITEC113 Algorithms and Programming Techniques
Basic Elements of C++.
Chapter 2 - Introduction to C Programming
By: Syed Shahrukh Haider
Introduction to C Programming
Basic Elements of C++ Chapter 2.
Operators and Expressions
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Chapter 2 - Introduction to C Programming
Lecture3.
Chapter 3 Operators and Expressions
Programs written in C and C++ can run on many different computers
Introduction to C Programming
Chapter 2 - Introduction to C Programming
OPERATORS in C Programming
DATA TYPES There are four basic data types associated with variables:
Introduction to C Programming
OPERATORS in C Programming
Presentation transcript:

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1

Week 2 Introduction to C Programming Outline A Simple C Program: Printing a Line of Text Data Types Another Simple C Program: Adding Two Integers Arithmetic in C Decision Making: Equality and Relational Operators

2.1Recap: a simple program is the header file containing basic commands needed to write programs Comments (xxxx) are inside the signs /* xxxx */ You put it for another programmer to read, and the computer will ignore your comments 5. Enter the following codes in the editor window #iain() { #include void main() { /*Comments, for humans to read and computers to ignore, go here */ printf(" Computer Programming for Engineers!\n"); } #include

2.1 More on Simple Program void main() You need to have only 1 main() program in your project void means the program does not return anything { the codes are inside these brackets }

2.1 printf() printf( "Welcome to C!\n" ); Statement inside “ ” the quote is displayed Every executable statement needs to end with semicolon (;) Escape character (\) specifies the special character or commands that follows, e.g., \n, \t

2.1Common Escape-Character Sequences

#include void main() { /*Comments, for humans to read and computers to ignore, go here */ printf(" Computer Programming for Engineers!\n"); } 2.2Running the program

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2.2Data Types in C-Language Six Basic Types covered: 1) integer (-15, 1, 21, 385, 9180) 2) float ( , -1.2, 81.0, , 1000) 3) Octal (012 = 10, 027 = 23) 4) Hexadecimal (0x12 = 18) 5) Character (‘a’, ‘0’, ‘p’, ‘:’) 6) String (“the world”, “Facebook”, “LOL”) 8

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Declare before using it 9

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Standard (ANSI) C data type Most common intAn integer (4 Bytes, 32 bits) floatA floating point (real) number (32 bits) char (kar)A single byte of memory, enough to store a character Less common longAn integer of increase range and memory unsignedAn integer (positive and zero only) used to increase the range shortAn integer of reduced range (2 Bytes, 16 bits) doubleA floating point number of increased range(64 bits) long double, unsigned int, etc. 10

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Example 1: int vs. short int #include void main() { int num1 = 33000; short int num2= 33000; printf("The data is: %d \n",num1); printf("The data is: %d \n",num2); } = =

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Declare variables Examples int a; char boy = 'u'; short int num2= 32; intnum4, num1 = 0, num3; char ch1 = 'z', ch2, ch3 = '5'; float x = 1.456, y; 12

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Use the place holder to specify type and location of displayed data 13 %d (integer)

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 14

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Arithmetics + Add6+4 = 7 -Subtract6-4 = 2 *Multiply6*4 = 24 /divide integer6/4 = 1 float6/4=1.5 %mod (modulo reduction)6%4 = 2 15

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. A simple sum program #include void main() {int num1=10,num2=12,num3; char ch1='+'; num3 = num1 + num2; printf(" the sum of is: %d \n",num3); printf("Again the sum of %d + %d is: %d \n",num1,num2,num3); printf("Still,the sum of %d %c %d is: %d \n",num1,ch1,num2,num3); } 16

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Mathematical Precedence Rule 17 1() [] ->. :: Grouping, scope, array/member access 2 ! ~ - + * & ++x --x (most) unary operations, sizeof and type casts 3* / % Multiplication, division, modulo modulo 4+ -Addition and subtraction 5 >Bitwise shift left and right 6 >=Comparisons: less-than,... 7== != Comparisons: equal and not equal 8&Bitwise AND 9^Bitwise exclusive OR 10|Bitwise inclusive (normal) OR 11&&Logical AND 12||Logical OR 13 ?: Conditional expression Conditional expression (ternary operator)ternary operator 14 = += - = *= /= %= &= |= ^= >= Assignment operators 15,Comma operator

Example

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Shorthand notation 19

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Comparison 20 x == y i > 10 a + b != c

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Comparison 21

Enter two integers, and I will tell you the relationships they satisfy: is not equal to 7 3 is less than 7 3 is less than or equal to 7

Enter two integers, and I will tell you the relationships they satisfy: is not equal to is greater than is greater than or equal to 12 Enter two integers, and I will tell you the relationships they satisfy: is equal to 7 7 is less than or equal to 7 7 is greater than or equal to 7