Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Input, Process and Output Commands Session 3.

Similar presentations


Presentation on theme: "Advanced Input, Process and Output Commands Session 3."— Presentation transcript:

1 Advanced Input, Process and Output Commands Session 3

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

3  %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

4 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

5 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

6  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

7  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

8 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".

9 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()

10 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()

11 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


Download ppt "Advanced Input, Process and Output Commands Session 3."

Similar presentations


Ads by Google