Number Systems, Scalar Types, and Input and Output

Size: px
Start display at page:

Download "Number Systems, Scalar Types, and Input and Output"

Transcription

1 Number Systems, Scalar Types, and Input and Output Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types Floating-Point Numbers

2 Binary, Octal, Hexadecimal, and Decimal Binary Binary numbering system has only two possible values for each digit: 0 and 1. For example, binary number decimal number

3 Decimal Numbers Decimal The digits' weight increases by powers of 10. The weighted values for each position is determined as follows: For example, A decimal number 4261 can be thought of as follows. 4 * * * * 1 = = 4261 (decimal)

4 Binary Binary, Octal, Hexadecimal, and Decimal The digits' weight increases by powers of 2. The weighted values for each position is determined as follows: For example, binary 10 is decimal 2. the binary value represents the decimal value * * * * * * * * 1 = = 202 (decimal)

5 Binary Two s Complement The left-most bit is the sign bit. If it is 1, then the number is negative. Otherwise, it is positive. Give a negative value, represent it in binary two s complement form as follows. 1. write the number in its absolute value. 2. complement the binary number. 3. plus 1. Example, represent 2 in binary two s complement with 16 bits for short int. Binary value of 2: 0b Binary complement of 2: 0b Plus 1: +1 Binary two s complement representation of -2: 0b

6 Give binary two s complement form of a negative number, find the absolute value of the negative value as follows. 1. Complement the binary number. 2. Plus 1. Example, find the decimal value of (0b ) 2 in binary two s complement form with 16 bits. Binary two s complement (0b ) 2 Binary complement (0b ) 2 Plus 1 Absolute value: +1 (0b ) 2 = 2 10 Negative value: -2

7 Subtraction of a value in the computer can be treated as addition of its two s complement. For example, the subtraction of (2-2) can be performed as 2+(-2) as follows: 0b (binary representation of 2) 0b (two s complement representation of -2) 0b (2+(-2))

8 Example > short i, j > i = 0b > j = 0b > i+j 0

9 Octal The octal system is based on the binary system with a 3-bit boundary. The octal number system uses base 8 includes 0 through 7. The weighted values for each position is as follows: Binary to Octal Conversion Break the binary number into 3-bit sections from the least significant bit (LSB) to the most significant bit (MSB). Convert the 3-bit binary number to its octal equivalent. For example, the binary value equals to octal value ( ) 8.

10 2. Octal to Binary Conversion Convert the octal number to its 3-bit binary equivalent. Combine all the 3-bit sections. For example, the octal value equals to binary value Octal to Decimal Conversion To convert octal number to decimal number, multiply the value in each position by its octal weight and add each value together. For example, the octal value (167) 8 represents decimal value *64 + 6*8 + 7*1 = 119

11 Hexadecimal Similar to octal, the hexadecimal system is also based on the binary system but using 4-bit boundary. The hexadecimal number system uses base 16 including the digits 0 through 9 and the letters A, B, C, D, E, and F. The letters A through F represent the decimal numbers 10 through 15. For the decimal values from 0 to 15, the corresponding hexadecimal values are listed below. Decimal Hexadecimal F E D C B A

12 The weighted values for each position is as follows: The conversion between binary value and hexadecimal value is similar to octal number,but using four-bit sections. The hexadecimal value 20A represents decimal value * * *1 = 522

13 Following table provides all the information you need to convert from one type number into any other type number for the decimal values from 0 to16. Binary Octal Decimal Hex Binary Octal Decimal Hex A B C D E F

14 Character Set The character set in C includes the following members: the 26 uppercase letters of the Latin alphabet A B C D E F G H I J K L M N O P Q R S T U V W X Y Z the 26 lowercase letters of the Latin alphabet a b c d e f g h i j k l m n o p q r s t u v w x y z the 10 decimal digits the following 31 graphic characters! " # % & ' ( ) * +, -. / : ; < = >? [ \ ] ^ _ { } ~ \$ `

15 Comments Comments of a C program can be enclosed within a pair of delimiters /* and */. The symbol // will comment out a subsequent text terminated at the end of a line. For example, /* This is a comment */ /* This is a comment across multiple lines */ printf( Hello, world\n ); // This is a comment terminated at the end of line

16 Declaration An identifier for a variable shall consist of lowercase and uppercase letters, underscore _, and digits. It shall not start with digits. A variable has to be declared before it can be used inside a program. The following format can be used to declare a variable of simple type. datatype varname; where datatype is one of valid data types and varname is an identifier. int main() { int i; i = 90; int j; j = 20; return 0; }

17 Data Types and Constants Integer Data Types Integer is a basic data type and can be represented by one of the following data types. char signed char unsigned char short signed short unsigned short int signed int unsigned int long signed long unsigned long long long signed long long unsigned long long

18 The sizeof operator gives the size of types or expression in bytes. One byte equals 8 bits. > int i > sizeof(int) 4 > sizeof(i) 4 > sizeof(2*i) 4 > sizeof(long long) 8

19 Int Data Representation An int data is a signed integer. An int number is a whole number that can be negative, positive, or zero. An int data uses 4 bytes for storage with 1 bit for the sign. The int ranges from INT_MIN to INT_MAX, which are ( 2 31 ) and (2 31 1), respectively. The unsigned int ranges from 0 to UINT_MAX, which is equal to (2 32 1). INT_MAX 0b INT_MIN 0b UINT_MAX 0b

20 Program: limits.c Output: #include <stdio.h> #include <limits.h> Int main() { printf( INT_MAX = %d\n, INT_MAX); printf( INT_MIN = %d\n, INT_MIN); printf( UINT_MAX = %d\n, UINT_MAX); return 0; } INT_MAX = INT_MIN = UINT_MAX =

21 Short Data Representation A short data uses 2 bytes for storage. The macros for minimum and maximum values of signed short are SHRT_MIN and SHRT_MAX defined in header file limits.h. SHRT_MIN is equal to (-2 15 ) and SHRT_MAX is equal to 32767(2 15-1). The macro USHRT_MAX, defined in the header file limits.h, specifies the maximum value of unsigned short. It is equal to 65535(2 16-1).

22 Long Long Data Representation Data of long long integral type contains 8 bytes. They have the similar representation as the data type of int. The long long int ranges from LLONG_MIN to LLONG_MAX, which are LL (-2 63 ) and LL (2 63 1), respectively. The long long int ranges from 0 to ULLONG_MAX, which is

23 Integer Constants An integer can be specified in decimal, binary, octal, or hexadecimal. A leading 0(zero) on an integer constant indicates an octal integer. A leading 0x or 0X indicates a hexadecimal integer. A leading 0b or 0B indicates a binary integer (in Ch only). Example: 30 (decimal) = 036 (octal) = 0X1e or 0x1E (hexadecimal) = 0b11110 or 0B11110 (binary)

24 Example: C:/Ch> int i C:/Ch> i = C:/Ch> i = 0x1e 30 C:/Ch> i = 0b C:/Ch> printf( i = %d\n, i) i = 30 C:/Ch> printf( i = 0%o\n, i) i = 036 C:/Ch> printf( i = 0x%x\n, i) i = 0x1e C:/Ch> printf( i = 0b%b\n, i) i = 0b11110

25 Boolean Type The keyword bool of a declarator in header file stdbool.h can be used to declare variables with boolean data type. For example, the following statement bool b; declares a boolean variable b. A boolean variable only has only two possible values: 1 and 0. Value 1 stands for true and value 0 stands for false. Macro true and false are defined in header file stdbool.h.

26 Char Data Representation The char data are used to store characters such as letters and punctuation. An array of char can be used to store a string. A character is stored as an integer according to a certain numerical code such as the ASCII code that ranges from 0 to 127, which only requires 7 bits to represent it. Typically, a char constant or variable occupies 1-byte (8 bits) of unit memory. Memory Address Binary value Character H e l l o !

27 The macros for minimum and maximum values of signed char are CHAR_MIN and CHAR_MAX defined in header file limits.h. CHAR_MIN is equal to -128(-2 7 ) and CHAR_MAX is equal to 127(2 7-1). The macro UCHAR_MAX, defined in the header file limits.h, specifies the maximum value of unsigned short. It is equal to 255(2 8-1). CHAR_MAX = 127 0b CHAR_MIN = b UCHAR_MAX = 255 0b

28 Character Constants A character constant, stored as an integer, can be written as one character within a pair of single quotes like x. A character constant can be assigned to the variable of type char. For example, > char c = x > c x

29 Escape Characters Escape Code Description \a (alert) Produces an audible or visible alert. The active position shall not be changed. \b (backspace) Moves the active position to the previous position on the current line. \f (form feed) Moves the active position to the initial position at the start of the next logical page. \n (new line) Moves the active position to the initial position of the next line. \r (carriage return) Moves the active position to the initial position of the current line. \t (horizontal tab) Moves the active position to the next horizontal tabulation position on the current line. \v (vertical tab) Moves the active position to the initial position of the next vertical tabulation position. \\ (backslash) Produces a backslash character \. \ (single quote) Produces a single quote character. \ (double quote) Produces a double quote character. \? (question mark) Produces a question mark character?.

30 String Literals A character string literal is a sequence of zero or more multibyte characters enclosed in double quotes, such as xyz. Remember that strings represented as character arrays end with \0. Using an array of characters to define a string variable. > char str1[6] = abcde // The last one is \0 > char str2[] = This is a string.

31 Arithmetic operations of two integers are still an integer > > 3/2 1 > 2/3 0 > 2.0/

32 Floating-Point Types Floating-point numbers have three representations: float, double, and long double. The float data type uses 32 bits (4 bytes) for its storage. The minimum and maximum values of float data type are defined as macros FLT_MIN and FLT_MAX, respectively, in header file float.h. The double data type uses 64 bits(8 bytes) as its storage. The minimum and maximum values of double data type are defined as macros DBL_MIN and DBL_MAX, respectively, in header file float.h The long double should have at least as many bits as double.

33 Metanumbers Below is a list of metanumbers for floating-point numbers and their mathematical equivalent. Metanumbers Mathematical Representation Inf - +Inf + NaN Not-a-Number (Invalid value)

34 Examples for NaN and Inf > 0.0/0.0 nan > 1.0/0.0 inf > -1.0/0.0 -inf > sqrt(4) > sqrt(-4) nan

35 Printing Multiple Numerical Values in a Single Printing Statement Use multiple format specifiers. Each format specifier corresponds to an argument. > printf( integer is %d, floating-point number is %f, 10, 12.34) integer is 10, floating-point number is

36 Precision of Floating-Point Numbers The precision of a floating-point number specifies the number of digits after the decimal point character. The precision typically takes the form of a period (.) followed by an decimal integer. For example, the format %.2f specifies the precision with 2 digits after the decimal point. > printf( %.2f, ) > printf( %.2f, ) > printf( %.20f, 0.2) The fractional part after the specified precision number is rounded up. A floating-point number may not be represented exactly.

37 Field Width of Numbers The field width is the size of a field in which data are printed. An integer width is inserted between % and the conversion specifier to indicate the field width For example, %6d specifies the field width of 6 for an integer, 8.4 specifies a field width of 8 with 4 digits after the decimal point. > printf( %6d, 12) 12 > printf( %8.4f, ) To print a %, use %% in the format string. > printf( 10%% of 100 is 10\n ) 10% of 100 is 10

38 Function scanf() Precise formatting input is accomplished using the input function scanf. The scanf function has following form scanf( format-control-string, arguments ); Format-control-string: Using specifications to describe input format. Each specification begins with a percent sign(%), ends with conversion specifier and is enclosed in quotation marks. The format-control-string is similar to format-control-string discussed in printf function. arguments: pointers to variables in which the input value will be stored.

39 Table below lists the format-control-string of different argument types for function scanf(). Using an extra \n such as %d\n is a common mistake. char short unsigned short int unsigned int long long Argument Type unsigned long long %c %hd %uhd %d %u %lld %ulld Format-Control-String float double string pointer %f %lf %s %p

40 Example: > int i > float f > double d > char c > scanf( %d, &i); 10 > i 10 > scanf( %f, &f); 10.2 > f > scanf( %lf, &d); 15 > d > scanf( %c, &c); a > c a

41 Example: > int i > scanf( %d, &i); // input number in decimal 4261 > Long long l > scanf( %lld, &l); // input into long long number 4261 > l 4261 > scanf( %b, &i); // input number in binary in Ch // or 0b > i 4261 > scanf( %o, &i); // input number in octal // or > i 4261 > scanf( %x, &i); // input number in hexadecimal 10A5 > i 4261 // or 0x10A5 or 0X10A5

42 Example: Program scanf.c /* File: scanfc.c for input and output example */ #include <stdio.h> int main() { int num; double d; } printf("please input an integer and one floating-point number\n); scanf("%d%lf",&num, &d); printf("your input values are %d and %f\n, num, d); return 0; Interactive execution of program scanf.c > scanfc.c Please input one integer and one floating-point number Your input number is 10 and >

공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -VARIABLE AND DATA TYPES- SPRING 2015, SEON-JU AHN, CNU EE

공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -VARIABLE AND DATA TYPES- SPRING 2015, SEON-JU AHN, CNU EE COMMENT Comment Comments are usually added with the purpose of making the source code easier to

ESC101N Fundamentals of Computing

ESC101N Fundamentals of Computing Arnab Bhattacharya arnabb@iitk.ac.in Indian Institute of Technology, Kanpur http://www.iitk.ac.in/esc101/ 1 st semester, 2010-11 Tue, Wed, Fri 0800-0900 at L7 Arnab Bhattacharya

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

Data Type Fall 2014 Jinkyu Jeong

Data Type Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Syntax Rules Recap. keywords break double if sizeof void case else int static... Identifiers not#me scanf 123th printf _id so_am_i gedd007 Constants

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

THE INTEGER DATA TYPES STORAGE OF INTEGER TYPES IN MEMORY All data types are stored in binary in memory. The type that you give a value indicates to the machine what encoding to use to store the data in

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

Work relative to other classes

Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 TYPES TYPES Programs have to store and process different kinds of data, such as integers and floating-point numbers, in different ways. To this end, the compiler needs to

Internal representation. Bitwise operators

Computer Programming Internal representation. Bitwise operators Marius Minea marius@cs.upt.ro 26 October 2015 Ideal math and C are not the same! In mathematics: integers Z and reals R have unbounded values

Types, Variables, and Constants

, Variables, and Constants What is a Type The space in which a value is defined Space All possible allowed values All defined operations Integer Space whole numbers +, -, x No divide 2 tj Why Types No

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

Internal representation. Bitwise operators

Computer Programming Internal representation. Bitwise operators Marius Minea marius@cs.upt.ro 23 October 2017 Ideal math and C are not the same! In mathematics: integers Z and reals R have unbounded values

Internal representation. Bitwise operators

Computer Programming Internal representation. Bitwise operators Marius Minea marius@cs.upt.ro 24 October 2016 Ideal math and C are not the same! In mathematics: integers Z and reals R have unbounded values

Basic Types and Formatted I/O

Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but

File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

CS107, Lecture 2 Bits and Bytes; Integer Representations

CS107, Lecture 2 Bits and Bytes; Integer Representations reading: Bryant & O Hallaron, Ch. 2.2-2.3 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons

Computer System and programming in C

1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

Chapter 7. Basic Types

Chapter 7 Basic Types Dr. D. J. Jackson Lecture 7-1 Basic Types C s basic (built-in) types: Integer types, including long integers, short integers, and unsigned integers Floating types (float, double,

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

CS107, Lecture 3 Bits and Bytes; Bitwise Operators reading: Bryant & O Hallaron, Ch. 2.1 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons Attribution

Reserved Words and Identifiers

1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

ECE 120 Midterm 1 HKN Review Session Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location: Your Room on Compass What to bring: icard, pens/pencils, Cheat sheet (Handwritten) Overview of Review Binary IEEE

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

Lecture 2 Tao Wang 1

Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Standard 11 Lesson 9 Introduction to C++( Up to Operators) 2MARKS 1. Why C++ is called hybrid language? C++ supports both procedural and Object Oriented Programming paradigms. Thus, C++ is called as a

BSM540 Basics of C Language

BSM540 Basics of C Language Chapter 3: Data and C Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture Explained the structure of a simple C program Introduced comments in

Types, Operators and Expressions

Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

Basic Elements of C. Staff Incharge: S.Sasirekha

Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase

The C++ Language. Arizona State University 1

The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

The New C Standard (Excerpted material)

The New C Standard (Excerpted material) An Economic and Cultural Derek M. Jones derek@knosof.co.uk Copyright 2002-2008 Derek M. Jones. All rights reserved. 303 5.2.4.2.1 Sizes of integer types

Types, Operators and Expressions

Types, Operators and Expressions CSE 2031 Fall 2011 9/11/2011 5:24 PM 1 Variable Names (2.1) Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

CSc Introduction to Computing

CSc 10200 Introduction to Computing Lecture 2 Edgardo Molina Fall 2011 - City College of New York Thursday, September 1, 2011 Introduction to C++ Modular program: A program consisting of interrelated segments

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

BITG 1233: Introduction to C++

BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 07: Data Input and Output Readings: Chapter 4 Input /Output Operations A program needs

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

Programming in C and Data Structures [15PCD13/23] 1 PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Course objectives: The objectives of this course is to make students

6.096 Introduction to C++ January (IAP) 2009

MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

C Fundamentals & Formatted Input/Output adopted from KNK C Programming : A Modern Approach C Fundamentals 2 Program: Printing a Pun The file name doesn t matter, but the.c extension is often required.

THE FUNDAMENTAL DATA TYPES

THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include

Unit 4. Input/Output Functions

Unit 4 Input/Output Functions Introduction to Input/Output Input refers to accepting data while output refers to presenting data. Normally the data is accepted from keyboard and is outputted onto the screen.

INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 printf and scanf Streams (input and output)

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. A Simple Program. simple.c: Basics of C /* CPE 101 Fall 2008 */ /* Alex Dekhtyar */ /* A simple program */ /* This is a comment!

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types

Programming. Elementary Concepts

Programming Elementary Concepts Summary } C Language Basic Concepts } Comments, Preprocessor, Main } Key Definitions } Datatypes } Variables } Constants } Operators } Conditional expressions } Type conversions

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

COP 3275: Chapter 07. Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA

COP 3275: Chapter 07 Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA Basic Types C s basic (built-in) types: Integer types, including long integers, short integers, and unsigned integers

Programming Language A

Programming Language A Takako Nemoto (JAIST) 26 November Takako Nemoto (JAIST) 26 November 1 / 12 Type char char is a datatype for characters. char express integers in certain region. For each ASCII character,

Numeric Data Types in C

Numeric Data Types in C Kernighan & Ritchie - Chapter 2, Types, Operators, and Expressions (Binary) Integers - Counting char / unsigned char - a.k.a. signed char, unsigned char - Yes, you can do arithmetic

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions Mr. Dave Clausen La Cañada High School Vocabulary Variable- A variable holds data that can change while the program

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

DECLARATIONS Character Set, Keywords, Identifiers, Constants, Variables Character Set C uses the uppercase letters A to Z. C uses the lowercase letters a to z. C uses digits 0 to 9. C uses certain Special

Data Types and Variables in C language

Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

JAVA Programming Fundamentals

Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Q1. Explain the structure of a C program Structure of the C program is shown below: Preprocessor Directives Global Declarations Int main (void) Local Declarations Statements Other functions as required

INTRODUCTION 1 AND REVIEW

INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

Java Basic Datatypees

Basic Datatypees Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable,

Fundamental of Programming (C)

Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . \$, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

AWK - PRETTY PRINTING

AWK - PRETTY PRINTING http://www.tutorialspoint.com/awk/awk_pretty_printing.htm Copyright tutorialspoint.com So far we have used AWK's print and printf functions to display data on standard output. But

Variables and Literals

C++ By 4 EXAMPLE Variables and Literals Garbage in, garbage out! To understand data processing with C++, you must understand how C++ creates, stores, and manipulates data. This chapter teaches you how

Computer Organization & Systems Exam I Example Questions

Computer Organization & Systems Exam I Example Questions 1. Pointer Question. Write a function char *circle(char *str) that receives a character pointer (which points to an array that is in standard C

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.

Fundamental of C programming. - Ompal Singh

Fundamental of C programming - Ompal Singh HISTORY OF C LANGUAGE IN 1960 ALGOL BY INTERNATIONAL COMMITTEE. IT WAS TOO GENERAL AND ABSTRUCT. IN 1963 CPL(COMBINED PROGRAMMING LANGUAGE) WAS DEVELOPED AT CAMBRIDGE

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

Programming and Data Structures

Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()

2. Numbers In, Numbers Out

COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break

EECS2031. Modifiers. Data Types. Lecture 2 Data types. signed (unsigned) int long int long long int int may be omitted sizeof()

Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

Programming in C Quick Start! Biostatistics 615 Lecture 4

Programming in C Quick Start! Biostatistics 615 Lecture 4 Last Lecture Analysis of Algorithms Empirical Analysis Mathematical Analysis Big-Oh notation Today Basics of programming in C Syntax of C programs

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

Number Representation 3/2/01 Lecture #

Number Representation 3/2/01 Lecture #11 16.070 How are numbers represented in a computer? Data come in two basic types! Numbers Whole/Integer (1, -3, 0) Natural, Positive (1, 2, 3) Real/Floating-point

2. Numbers In, Numbers Out

REGZ9280: Global Education Short Course - Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. REGZ9280 14s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write

C Programming

204216 -- C Programming Chapter 3 Processing and Interactive Input Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives Assignment Mathematical Library

printf( Please enter another number: ); scanf( %d, &num2);

CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

Fundamentals of Programming

Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

CS 150 Introduction to Computer Science I Data Types Today Last we covered o main function o cout object o How data that is used by a program can be declared and stored Today we will o Investigate the

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

Presented By : Gaurav Juneja

Presented By : Gaurav Juneja Introduction C is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs of UNIX are written

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

PYTHON- AN INNOVATION

PYTHON- AN INNOVATION As per CBSE curriculum Class 11 Chapter- 2 By- Neha Tyagi PGT (CS) KV 5 Jaipur(II Shift) Jaipur Region Python Introduction In order to provide an input, process it and to receive

Programming in C++ 4. The lexical basis of C++

Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++

Fundamentals of Programming. Lecture 11: C Characters and Strings

1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

1 Literal Constants Definition A literal or a literal constant is a value, such as a number, character or string, which may be assigned to a variable or a constant. It may also be used directly as a function

Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

LECTURE 02 INTRODUCTION TO C++

PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

Lecture 3. More About C

Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

CS102: Variables and Expressions

CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of