Programming

Just another WordPress.com weblog

ข้อสอบ CT203 – ข้อย่อยที่ 2 เรื่อง algorithm (ปี 2008)

แสดงความเห็นโดย จั่น บน กรกฎาคม 17, 2008

a1*a1+a1*a2+a1*a3+…….+a1*an

a2*a1+a2*a2+a2*a3+…….+a2*an

a3*a1+a3*a2+a3*a3+…….+a3*an

…………

an*a1+an*a2+an*a3+…….+an*an

**หมายเหตุ ในข้อสอบตัวเลขหลังตัว a จะเยื้องลงมาด้านขวาล่างของตัว a ทุกตัว

จงเขียน algorithm หาผลรวมทั้งหมดนี้แล้วหารด้วยจำนวนทั้งหมดที่นำมาบวกกัน (หาค่าเฉลี่ย Means)

void CalculateMeans(int[] a){

int sum = 0;

for(int i=1; i<=n; i++){

for(int j=1; j<=n; j++){

sum += a[i]*a[j];

}

}

cout << “Means = ” << sum/(n * n) ;

}

ใส่ความเห็น

XHTML: คุณสามารถใช้แท็กเหล่านี้ได้: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>