วันพฤหัสบดีที่ 15 กรกฎาคม พ.ศ. 2553

B05.ฟังก์ชัน printf()

ฟังก์ชัน printf()
ฟังก์ชัน printf() เป็นฟังก์ชันจากคลัง ที่มาพร้อมกับตัวโปรแกรมภาษาซี ใช้สำหรับการแสดงผล แบ่งเป็น 2 รูปแบบดังนี้

1. การแสดงเฉพาะข้อความ

printf("ข้อความ");

ตัวอย่าง


#include
int main (void){

printf("Hello World");
system("pause");

}


2. การแสดงผลและการรับค่า

printf("สายอักขระความคุม",ตัวแปร) ;

ตัวอย่าง


#include
int main (void){

printf("Number is :%d",10);
system("pause");

}

3. การใช้ printf() ร่วมกับ \n
3.1.
Coding:

#include
int main (void){

printf("*****");
printf("\n");
system("pause");

}

Output:

*****
Press any key to continue . ...

3.2.
Coding:

#include
int main (void){

printf("*****\n");
system("pause");

}

Output:

*****
Press any key to continue . ...

ไม่มีความคิดเห็น:

Popular Posts