2.設計一程式,依照下列公式計算sum的值,並將其值印出
sum=a[0]*b[9]+a[1]*b[8]+‧‧‧+a[9]*b[0]
int a[]={18,-51,23,35,10,9,-3,52,81,69};
int b[]={28,32,-35,40,73,17,92,32,13,29};
1 2 3 4 5 6 7 8 | int a[]={18,-51,23,35,10,9,-3,52,81,69}; int b[]={28,32,-35,40,73,17,92,32,13,29}; int sum=0; for(int i=0;i<a.length;i++){ int j=(b.length-1)-i; sum+=a[i]*b[j]; } System.out.println("sum="+sum); |
sum=7226
沒有留言:
張貼留言