วันศุกร์ที่ 20 กันยายน พ.ศ. 2556

=Fuction=(Hard)

Programming Exercise
Proposition => Write the code for a function that receives four integers. The function should calculate the average of the four integer, and the return result .name the function calcAverage()

Translated into Thailand =>
เขียนโค้ดสำหรับ ฟังก์ชั่นที่รับจำนวนเต็ม 4 จำนวน,เป็นฟังก์ชั่นที่ใช้คำนวนหาค่าเฉลี่ย ของสี่จำนวนและรีเทิร์นค่า โดยใช้ชื่อฟังก์ชั่นcalcAverage()

Solution=> 

void setup() {
  println(calcAverage(7,18,15,29));  //แสดงค่าออกมาทางหน้าจอโดยค่าที่แสดง
                                                         ได้จากการเรียกใช้ฟังก์ชันcalcAverage( )
}

float calcAverage(int a,int b,int c,int d) { //สร้างฟังก์ชันโดยกำหนดให้มีการ return ค่ากลับ และมีparameter
  return (a+b+c+d)/4;
}


Out put =>  17.0

You can run code in http://processingjs.org/tools/processing-helper.html



text book name :Programming and problem solving with Java – 2nd edition
Author : Nell Dale and Chip Weems
              ISBN 978-0-7637-3402-2

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

แสดงความคิดเห็น