14 กันยายน 2558

Lab4 Sum of Integers

void setup() {
  size(300, 100);
  background(0);
  int max_val = 99;
  int x=0;
  int sum=0;
  while (x <= max_val) {
    sum += x;
    x++;
  }
  textSize(18);
  textAlign(CENTER);
  text("Sum of Integers from 1 to "+max_val, width/2, height/2-20);
  text("'"+sum+"'", width/2, height/2+20);
}

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

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