Page 948 - เตรียมสอบครูผู้ช่วยคอมพิวเตอร์_compressed
P. 948

ึ
                                                                  ี
                                                                  ่
                                                                เฉลยแบบฝกหัดหน่วยท 6

               จงตอบคําถามต่อไปน    ี ้
                                               ่
               1. จงแสดงผลการรันของโปรแกรมตอไปน     ้ ี
               #include <stdio.h>

               void main( ) {
                       int y, count;

                       count = 1;
                       y = count++;

                       printf(“y = %d, count = %d\n”, y, count);
                       y = ++count;

                       printf(“y = %d, count = %d”, y, count);
               }

                       แนวตอบ ใช้แนวทางการเขียนโปรแกรม         โครงสร้างแบบลําดับ
                จะได้ผลลัพธ์         y = 1, count = 2

                                     y = 3, count = 3

                                                       ้
               2. จงเขียนโปรแกรมรับค่าตัวเลขเข้ามาทางแปนพิมพ์ 2 ค่า แล้วนามาคูณกัน จากนั้นแสดงผลลัพธ์ออก
                                                                        ํ
                      ้
               ทางหนาจอ
                       แนวตอบ ใช้แนวทางการเขียนโปรแกรม         โครงสร้างแบบลําดับ
                จะได้ผลลัพธ์

                       #include <stdio.h>
                       void main(){

                              int Num1, Num2, Mul;
                              printf("Please enter first number : ");

                              scanf("%d", &Num1);
                              printf("Please enter second number : ");

                              scanf("%d", &Num2);
                              Mul = Num1 * Num2;

                              printf("Result %d x %d = %d", Num1, Num2, Mul);
                       }









                                                                                                         5
   943   944   945   946   947   948   949   950   951   952   953