📄 l42.1a
字号:
#printWrite a function inprod(a,b,n)that computes the inner product of two integer vectorsa and b which are n items long. Name the file "inprod.c"and compile and test it; then type ready.You may assume that the result and all intermediatevalues fit in a 16-bit integer, not usually a safe assumption.#once #create tzaqc.cmain(){ int x[100], y[100]; int k; for(k=0; k<100; k++) { x[k] = k%10; y[k] = (k*k)%3; } if (inprod(x,y,100) != xprod(x,y,100)) return(1); return(0);}xprod(x,y,n) int *x, *y;{ int k, sum; for(sum=k=0; k<n; k++) sum=+ *x++ * *y++; return(sum);}#usercc tzaqc.c inprod.oa.out#succeed/* one way */inprod(a, b, n)int *a, *b;{ int s; s = 0; while (n--) s += *a++ * *b++;/* none of the spaces in the line above are necessary but would you really want to read s+=*a++**b++; and try to parse it? Even clearer than what I have, but slower, would be for(i=0; i<n; i++) s += a[i]*b[i];*/ return(s);}#log#next43.1a 10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -