1 / 16

Programming With C

Programming With C. Data Input & Output. Printing Data. Printing Data from Program printf( ) putchar( ). putchar( ) Function. รูปแบบการใช้งานฟังก์ชั่น putchar( charVarName ) ; Ex.. char c1 = ‘A’ , c2 = ‘B’ ; putchar(c1) ; putchar(c2) ;. printf( ) Function.

Télécharger la présentation

Programming With C

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. Programming With C Data Input & Output

  2. Printing Data Printing Data from Program • printf( ) • putchar( )

  3. putchar( ) Function • รูปแบบการใช้งานฟังก์ชั่น putchar( charVarName ) ; Ex.. char c1 = ‘A’ , c2 = ‘B’ ; putchar(c1) ; putchar(c2) ;

  4. printf( ) Function • รูปแบบการใช้งานฟังก์ชั่น printf(“control string”) ; printf(“control string”, var1,var2,….) ; control string หมายถึงข้อความ, รหัสชนิดข้อมูลและรหัสควบคุมการแสดงผล

  5. printf( ) Function รหัสชนิดข้อมูล

  6. printf( ) Function รหัสควบคุมการแสดงผล(Escape Sequences)

  7. printf( ) Function int a = 100 ; float fp = 12.5 ; char ch = ‘w’ ; printf(“a = %d”,a); printf(“fp = %f\tch = %c\n”,fp,ch) ;

  8. Entering Data Entering Data into Program • scanf( )  รับข้อมูลตัวเลข ตัวอักษรและสตริง • getchar( )  รับข้อมูลตัวอักษร • getch( ) รับข้อมูลตัวอักษร • getche( )  รับข้อมูลตัวอักษร

  9. Character Input • getchar( ) CharVarName = getchar( ) ; • getch( ) CharVarName = getch( ) ; • getche( ) CharVarName = getche( ) ;

  10. Character Input #include<stdio.h> #include<conio.h> void main() { char c1, c2, c3; printf("Enter c1 : "); c1 = getchar(); printf("Enter c2 : "); c2 = getch(); printf("Enter c3 : "); c3 = getche(); printf("\n\nc1 ; %c, c2 = %c, c3 = %c\n",c1,c2,c3); }

  11. scanf( ) Function รูปแบบการใช้งานฟังก์ชั่น scanf(“control code”,&var1,&var2, …) ; control code หมายถึงรหัสชนิดข้อมูล และรหัสควบคุม (ใช้รหัสเช่นเดียวกับฟังก์ชั่น printf)

  12. scanf( ) Function int a; float b; char c; printf(“Enter an integer number : “) ; scanf(“%d”,&a); printf(“Enter a float and character : “); scanf(“%f\t%c”,&b,&c) ;

  13. String input and output • String input gets(stringName) ; scanf(“%s”,stringName) ; • String output puts(stringName) ; printf(“%s”,stringName) ;

  14. String input and output String  Array of Character char name1[20] , name2[20] ; gets(name1) ; scanf(“%s”,name1) ; puts(name1) ; printf(“%s”,name2) ;

  15. More about prntf( ) int a = 123 ; float b = 123.456 ; printf(“%d %f”,a,b) ; printf(“%10d %10.3f”,a,b) ; printf(“%-10d %-10.3f”,a,b) ;

  16. Assignment • เขียนโปรแกรมเพื่อรับค่าข้อมูลและคำนวณหาพื้นที่รูปสามเหลี่ยม • เขียนโปรแกรมเพื่อรับค่าตัวเลขจำนวนเต็ม 10 ตัว และทำการคำนวณหาค่าผลรวมและค่าเฉลี่ย

More Related