1 / 11

Advanced Input , Process and Output Commands

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

hovan
Download Presentation

Advanced Input , Process and Output Commands

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Input, Process and Output Commands Session 3

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

  3. 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.

  4. Table of scanf Format Specifier

  5. Table of printf Format Specifier

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

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

  8. Table of Escape Sequences

  9. 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(); • }

  10. 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(); • }

  11. 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 : ... ...

More Related