110 likes | 202 Views
Advanced Input , Process and Output Commands. Session 3. Input – Output Command. Input scanf(“%d”,&a); gets(nm_mhs); sex = getch(); Output printf(“%d”,a) puts(“Nama Anda : “+nm_mhs); putchar(sex);. Format Specifier. %d is called Format Specifier
E N D
Input – Output Command • Input • scanf(“%d”,&a); • gets(nm_mhs); • sex = getch(); • Output • printf(“%d”,a) • puts(“Nama Anda : “+nm_mhs); • putchar(sex);
Format Specifier • %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.
Escape Sequences • 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.
Exercise 1 scanf() • /* • Syntax : • scanf(“format specifier",&variabelname); • */ • #include <stdio.h> • #include <conio.h> • #include <string.h> • void main() • { //deklarasi variabel • clrscr(); • //input • printf("Nama Mahasiswa : "); • printf(“Jenis Kelamin [L/P] : "); • printf(“Tinggi Badan : "); • printf(“Tahun Lahir : “); • //proses cari umur • //cetak output • getch(); • }
Exercise 2 printf() • /* ContohPenggunaan Escape Sequence & Penentu Format • \t = tabulasi, \n = pindahbaris • %6.2f = 6 digit 2 desimaluntuk format float */ • #include <stdio.h> • #include <conio.h> • void main() • { • float bil1=3.14,bil2=8.50,bil3=88.0; • float bil4=13.7,bil5=70.80,bil6=100.45; • clrscr(); • printf("\'NKR\' Singkatandari \"NayaKartikaRamadhani\" \n\n"); • printf("\n Tekan Enter...!\n\n");getch(); • printf("Escape Sequence tab(\\t) \n"); • printf("------------------------\n"); • printf("%6.2f \t%6.2f \t%6.2f \n",bil1,bil2,bil3); • printf("%6.2f \t%6.2f \t%6.2f \n",bil4,bil5,bil6); • printf("------------------------\n"); • getch(); • }
Task 3 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 2Data output : total, difference The desired view as follows: Enter Number 1 : ... ...Enter Number 2 : ... ...The number between ... and ... are : ... ...The difference between ... and ... are : ... ...