Advanced Input, Process and Output Commands Session 3.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
CSci 1130 Intro to Programming in Java
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
Chapter Three Arithmetic Expressions and Assignment Statements
Week 1.
Data Types Session 2.  Primitive data types  int, float, double, char  Aggregate data types  Arrays come.
Chapter 8 Improving the User Interface
Lecture 9. Lecture 9: Outline Strings [Kochan, chap. 10] –Character Arrays/ Character Strings –Initializing Character Strings. The null string. –Escape.
Dale Roberts Basic I/O – printf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
Printing. printf: formatted printing So far we have just been copying stuff from standard-in, files, pipes, etc to the screen or another file. Say I have.
Variables, Data Types and I/O in C
CS 161 Introduction to Programming and Problem Solving Chapter 13 Console IO Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Variable & Constants. A variable is a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
Basic Input - Output. Output functions  printf() – is a library function that displays information on-screen. The statement can display a simple text.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
Constants in C A Presentation On Department of Computer & Information Technology, M.S.P.V.L. Polytechnic College, Pavoorchatram.
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.
A First Book of ANSI C Fourth Edition Chapter 3 Processing and Interactive Input.
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Characters and Character Sets tMyn1 Characters and Character Sets The characters that can be used are the upper and lower case letters, A to Z and a to.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
C++ Basics Tutorial 5 Constants. Topics Covered Literal Constants Defined Constants Declared Constants.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
12/06/ :01:41 CSC Alliance — 1 Kimera Richard Phone: INSTITUTE OF COMPUTER SCIENCE DEPARTMENT.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
Chapter 9 - Formatted Input/Output
C Formatted Input/Output
Formatted Input/Output
ECE Application Programming
Standard Input - Output
Wel come.
TMF1414 Introduction to Programming
Formatted Input/Output
By: Syed Shahrukh Haider
OUTPUT STATEMENTS GC 201.
C Formatted Input / Output Review and Lab Assignments
توابع ورودي-خروجي.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
A First Book of ANSI C Fourth Edition
Chapter 9 - Formatted Input/Output
Chapter 4 Managing Input and Output Operations
Introduction to C Programming
Presentation transcript:

Advanced Input, Process and Output Commands Session 3

 Input  scanf(“%d”,&a);  gets(nm_mhs);  sex = getch();  Output  printf(“%d”,a)  puts(“Nama Anda : “+nm_mhs);  putchar(sex); Input – Output Command

 %d is called Format Specifier  Use of determining the format is associated with the type of data to be printed, meaning each has a data type determines the format of each. The following table is a table determines the format for each type of data. Format Specifier

Table of scanf Format Specifier NoTipe Data Format Specifier for scanf() 1Integer%d 2Floating Point  Bentuk Desimal%e atau %f  Bentuk Berpangkat%e atau %f 3Double Precision%lf 4Character%c 5String%s 6Unsigned Integer%u 7Long Integer%ld 8Long unsigned integer%lu 9Unsigned Hexadecimal Integer%x 10Unsigned Octal Integer%o

Table of printf Format Specifier NoData Types Format Specifier for printf() 1Integer%d 2Floating Point  Bentuk Desimal%f  Bentuk Berpangkat%e  Yang lebih pendek antara Desimal dan Berpangkat%g 3Double Precision%lf 4Character%c 5String%s 6Unsigned Integer%u 7Long Integer%ld 8Long unsigned integer%lu 9Unsigned Hexadecimal Integer%x 10Unsigned Octal Integer%o

 Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences. An escape sequence is regarded as a single character and is therefore valid as a character constant. Escape Sequences

 Escape sequences are typically used to specify actions such as carriage returns and tab movements on terminals and printers. They are also used to provide literal representations of nonprinting characters and characters that usually have special meanings, such as the double quotation mark ("). The following table lists the ANSI escape sequences and what they represent. Escape Sequences

Table of Escape Sequences Escape SequenceRepresents \aBell (alert) \bBackspace \fFormfeed \nNew line \rCarriage return \tHorizontal tab \vVertical tab \'Single quotation mark \"\"Double quotation mark \\Backslash \?Literal question mark \oooASCII character in octal notation \xhhASCII character in hexadecimal notation \xhhhh Unicode character in hexadecimal notation if this escape sequence is used in a wide-character constant or a Unicode string literal. For example, WCHAR f = L'\x4e00' or WCHAR b[] = L"The Chinese character for one is \x4e00".

1./* 2.Syntax : 3. scanf(“format specifier",&variabelname); 4. */ 5.#include 6.#include 7.#include 8.void main() 9.{ //deklarasi variabel 10. clrscr(); 11. //input 12. printf("Nama Mahasiswa : "); 13. printf(“Jenis Kelamin [L/P] : "); 14. printf(“Tinggi Badan : "); 15. printf(“Tahun Lahir : “); 16. //proses cari umur 17. //cetak output 18.getch(); 19.} Exercise 1 scanf()

1./* Contoh Penggunaan Escape Sequence & Penentu Format 2. \t = tabulasi, \n = pindah baris 3. %6.2f = 6 digit 2 desimal untuk format float */ 4.#include 5.#include 6.void main() 7.{ 8. float bil1=3.14,bil2=8.50,bil3=88.0; 9. float bil4=13.7,bil5=70.80,bil6=100.45; 10. clrscr(); 11. printf("\'NKR\' Singkatan dari \"Naya Kartika Ramadhani\" \n\n"); 12. printf("\n Tekan Enter...!\n\n");getch(); 13. printf("Escape Sequence tab(\\t) \n"); 14. printf(" \n"); 15. printf("%6.2f \t%6.2f \t%6.2f \n",bil1,bil2,bil3); 16. printf("%6.2f \t%6.2f \t%6.2f \n",bil4,bil5,bil6); 17. printf(" \n"); 18. getch(); 19.} Exercise 2 printf()

Create a program to calculate the sum and difference of two integers, then show the sum and difference was to use wide-format field = 8. Input data: number 1, number 2 Data output: total, difference The desired view as follows: Enter Number 1: Enter Number 2: The number between... and... are: The difference between... and... are: Task 3