วันอาทิตย์ที่ 23 สิงหาคม พ.ศ. 2558

Lab 2 : Calculate circumference and area of a rectangle (use function)


void setup() {
 size(400,200);
 background(255);

  int w=70;
  int h=150;
 
  textSize(15);
  fill(0);
  text("Value of a Area = "+area(w,h)+" cm*cm",40,40);
  text("Value of a Circumference = "+circum(w,h)+" cm.",40,80);
}

///// calculate area of rectangle /////

int area(int w,int h){

   int area;
   area = w*h;
   return area;

}

///// calculate circum of rectangle /////

int circum(int w,int h){

   int circum;
   circum = (2*w)+(2*h);
   return circum;

}

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

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