1 / 8

การแสดงผล และการรับข้อมูล

การแสดงผล และการรับข้อมูล. รหัสรูปแบบ (Format Code). %d สำหรับการแสดงผลตัวเลขจำนวนเต็ม %u สำหรับการแสดงผลตัวเลขจำนวนเต็มบวก %o สำหรับการแสดงผลออกมาในรูปแบบของเลขฐานแปด %x สำหรับการแสดงผลออกมาในรูปแบบของเลขฐานสิบหก %f สำหรับการแสดงผลตัวเลขทศนิยม

misae
Download Presentation

การแสดงผล และการรับข้อมูล

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. การแสดงผล และการรับข้อมูล

  2. รหัสรูปแบบ (Format Code) • %d สำหรับการแสดงผลตัวเลขจำนวนเต็ม • %u สำหรับการแสดงผลตัวเลขจำนวนเต็มบวก • %o สำหรับการแสดงผลออกมาในรูปแบบของเลขฐานแปด • %x สำหรับการแสดงผลออกมาในรูปแบบของเลขฐานสิบหก • %f สำหรับการแสดงผลตัวเลขทศนิยม • %e สำหรับการแสดงผลตัวเลขทศนิยมออกมาในรูปแบบ E • %c สำหรับแสดงผลอักขระ 1 ตัว • %s สำหรับแสดงผลข้อความ • %p สำหรับการแสดงผลตัวชี้ตำแหน่ง

  3. คำสั่งที่ใช้ในการแสดงผล และการรับข้อมูล printf() รูปแบบ printf (“ control “,value): control : ส่วนที่ใช้ควบคุมการแสดงผล ซึ่งมีอยู่ 3 แบบด้วยกัน คือ ข้อความ ธรรมดา รหัสควบคุมรูปแบบ (เช่น %d, %f) และอักขระควบคุมการแสดงผล (เช่น %n) โดยส่วนที่ใช้ควบคุมการแสดงผลเหล่านี้จะต้องเขียนไว้ภายใน “ “ value: คือ ค่าของเครื่องหมาย นิพจน์ หรือมาโครที่ต้องการแสดงผล โดย ถ้ามีมากกว่าหนึ่งตัวให้ใช้เครื่องหมาย , (comma) คั่นระหว่างแต่ละตัว

  4. ตัวอย่าง /*Ex1 */ #include <stdio.h> main() { printf (“Nice to meet you!”); } OUTPUT Nice to meet you! /*Ex2 */ #include <stdio.h> int num = 32; main() { printf (“%d” ,num); } 32 OUTPUT

  5. ตัวอย่าง /* EX 3 */ #include<stdio.h> main() { int x1=43,x2=0x77,x3=0573; float y1=-764.512,y2=1.25e02; char z='A'; char name[10]="Southeast"; clrscr(); printf("\n%d\n",x1); printf("%x\n%o\n",x2,x3); printf("%f\n%e\n",y1,y2); printf("%c\n%s\n",z,name); } OUTPUT

  6. อักขระควบคุมการแสดงผลอักขระควบคุมการแสดงผล • \n ขึ้นบรรทัดใหม่ • \t เว้นช่องว่างเป็นระยะ 1 Tab (6 ตัวอักษร) • \r กำหนดให้ Cursor ไปอยู่ต้นบรรทัด • \f เว้นช่องว่างเป็นระยะ 1 หน้าจอ • \b ลบอักขระตัวท้ายสุดออก 1 ตัว

More Related