0 喜歡 0 不喜歡
9k 瀏覽

Finish the function inner_product below. The function should return a[0] * b[0] + a[1] * b[1] + ... + a[n-1] * b[n-1]:

寫inner_product函數。函數會return a[0] * b[0] + a[1] * b[1] + ... + a[n-1] * b[n-1]:

#include <stdio.h>
double inner_product(double a[],double b[],int n)
{
   /*INSERT YOUR CODE HERE*/


   /*END OF YOUR CODE*/
   //The function should return a[0] * b[0] + a[1] * b[1] + ... + a[n-1] * b[n-1].
}

int main(void)
{
   double arrayA[100], arrayB[100];
   int c, n;

   scanf("%d", &n); //Enter number of elements in array
   for ( c = 0 ; c < n ; c++ )     //Enter array A
      scanf("%lf", &arrayA[c]);
   for ( c = 0 ; c < n ; c++ )     //Enter array B
      scanf("%lf", &arrayB[c]);

   printf("%g",inner_product(arrayA,arrayB,n));

   return 0;
}

Example input: 

The first input is the number of elements in arrays (3); The array values of A and B follow; 

第一行是陣列大小,第二行A元素,第三行B元素

3
4 7 8
1 2 3

Example output

42

Remember: You may correct the cases, but your code always be revised!

[練習] Coding (C) - 最新提問 分類:Chapter 9: Functions | 用戶: (5.2k 分)
ID: 37277 - 從幾時開始: 2017-12-14 18:00 - 到幾時結束: 無限制

修改於 用戶: | 9k 瀏覽

38 個回答

0 喜歡 0 不喜歡
內容已隱藏
#include * *** ****** *
double * *** a[],double b[],int n)
{
* ** * *** ** * * ** ** **
** ** * ** * **** * * i;
*** *** *** * * **** * * ****** * **
* * ** ** ** * ** * **
** ** ** * * *** result;
}

int main(void)
{
** ** ** * *** *** ** ** **** * **** *
***** **** * * * ** c, n;

* * ******* ** * ** * * * * * * * * * //Enter number of elements in array
***** * ** * * ** ( c = 0 ; c < n ; c++ ) *** ** ***** ** ** array A
* * * * ** ** * ***** * * ** *** *** ** * ****** ***** ***
* * * * * * ** *** ( c = 0 ; c < n ; c++ ) * ** ** *** * *** *** array B
* **** * ** ****** *** * **** ** ** ** * * * ** * * * * *

** * * ** * * **** *** *** * *** * * * * **

* ******* * * ** ** 0;
}
最新回答 用戶: (16 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include * **** **
double ***** *** * a[],double b[],int n)
{
* * ** * * * ***** * * c;
* * * ***** * ** * ** ******* sum=0;
** * **** ** ** * ***** ** ***
* * * *** ***
******** ** ** * * ** * * **** * ** ** *
******* **** ****
** * *** ** **** * ** sum;
}

int main(void)
{
* **** * * ***** * arrayA[100], arrayB[100];
* * * *** * c, n;

** ** ***** ** * ** * * ***** &n);
* * * ** * * ** ( c = 0 ; c < n ; c++ )
** * *** * ******* ** * **** ** * *** *** * ** * ** ** * * ** *
* ** * * * ***** ** ( c = 0 ; c < n ; c++ )
**** ** * * ** ** * * * ** ** * ******** * ** *** *** ***

*** * ** ** ** * ** * * * * ** *** * **** *** ** * * * *

* **** * ** 0;
}
最新回答 用戶: (-32 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 喜歡 0 不喜歡
內容已隱藏
* * ** *** **
* * ****** * * b[],int n)
{
* * *** * * ***** *** * * YOUR CODE HERE*/
* * * ** * * * i,sum = 0;
*** ** * * * ** * ** ** * ** ***
**** ** ** * ** * ** * *** ** ***** * ** ** * += *** *
* ** ** * * ** * * * * * sum;
* ** * *** ** * ********* OF YOUR CODE*/
*** ** ** * ** * * * * should return a[0] * b[0] + a[1] * b[1] + ... + a[n-1] * b[n-1].
}

int * **
{
***** ** ** *** * **** *** ** *
* * **** *** * * c, n;

****** ** ** * *** * * ** ** ** * * *** * * *** ** //Enter number of * in array
**** **** * ***** *** * ( c = 0 ; c ** n ; c++ ) * * *** * * ** * * ** * array A
* **** * * * *** * * ** * ** * * * **** **** * ** *
*********** * ** * * ( c = 0 ; c * n ; c++ ) ***** * * * * * * array B
* ** * * * *** ****** * * * ** * *** * **** ** ** * ******

* * ** * * ** ** *** * ** *** *** **** ***** * * ** *

* ** *** ** * * 0;
}
最新回答 用戶: (-281 分)
0 0
prog.c: In function 'inner_product':
prog.c:6:11: error: 'o' undeclared (first use in this function)
     for(i=o;i<n;i++)
           ^
prog.c:6:11: note: each undeclared identifier is reported only once for each function it appears in
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 喜歡 0 不喜歡
內容已隱藏
* * * **** ** * *
** ** *** *** * * *** b[],int n)
{
**** * ** * * * * ** * * YOUR CODE HERE*/
*** * * * * ** * ** i,sum = 0;
** * * **** * *** **** ******* * **
** **** * * * * **** ** ** * * *** ** ** ** ** * +=
* ****** * * *** * ** sum;
* ** **** * * ******** OF YOUR CODE*/
* *** ***** ** *** * * * should return a[0] * b[0] + a[1] * b[1] + ... + a[n-1] * b[n-1].
}

int ** * *
{
***** *** * **** ** * * ** ***** *
** * ** * * ** c, n;

* * ** ** * ** ***** ** ** *** * ** //Enter number of ** in array
* *** ** * * *** ***** ** ( c = 0 ; c **** n ; c++ ) * * *** * * *** * * * * **** array A
** * ** ** * ****** ***** * * * ** ** * ** * ** * **** *
* * * * * **** * * ( c = 0 ; c * ** ** n ; c++ ) ** ** * * * * * **** array B
****** ** ** ** * * * ** ** ** * ******** * ** * ** * ** * **

* ** **** * ** **** ** ** * * * *** *** *** * * *

* * * *** *** * 0;
}
最新回答 用戶: (-281 分)
0 0
prog.c: In function 'inner_product':
prog.c:6:11: error: 'o' undeclared (first use in this function)
     for(i=o;i<n;i++)
           ^
prog.c:6:11: note: each undeclared identifier is reported only once for each function it appears in
0 喜歡 0 不喜歡
內容已隱藏
#include * * * * **
double ******** * * * **** b[],int n)
{
* * * **** ***** * ** sum = 0, i;

***** *** * * * * *** * (i = 0; i < n; ++i)
* * * * ** * ** *** * ** **** ** * **** ** * * += *(a + i) * *(b + i);
* * * **** *** * **** *** sum;
}

int ***
{
* ** * * * *** ** * ****** ** **
* * * * ** * ***** c, n;

** * * *** * **** * * * * * ** ** * //Enter number of * ** in array
** * * **** ** * * * ( c = 0 ; c ** ** n ; c++ ) ** *** *** * * * ** array A
* *** ** * **** ** * ** ** **** *** ** * * * * * **
* * * ** * ** * ** * ( c = 0 ; c * * n ; c++ ) * ***** *** * array B
* * * * * ** **** * ** *********** ** ** * * *

* * * * * * * * * *** ** * * *** **** *** *

** * ** * *** * ** 0;
}
最新回答 用戶: (-108 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include * ** ***** *
double * *** * * ** *** b[],int n)
{
**** ** ** * **** sum = 0, i;

** ** **** ** * (i = 0; i < n; ++i)
** * ***** * *** ********** * * * **** += *(a + i) * *(b + i);
** * ** ******* ** * *** * ** sum;
}

int **
{
**** ****** * ** * * ** * * ***
** * ** ** * **** c, n;

* * * ** * * * * * *** * **** * //Enter number of *** in array
* * *** ** * * * ** ( c = 0 ; c * n ; c++ ) * ** ** * * * * * array A
**** *** ***** * * * ** * *** ** * * **** *** *** * * **
* ** ** * *** * ( c = 0 ; c *** n ; c++ ) ***** * *** * * * array B
** * ** * * * * * ** ** **** * * ** ** * ** * ** *** * **

* **** * ***** *** ** ** * * * * * * * * * * *

** * * * * ** 0;
}
最新回答 用戶: (-284 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include **** ** **
double ** ***** * ***** b[],int n)
{
** *** ** sum = 0, i;

***** * ******* * ** * * *** (i = 0; i < n; ++i)
* * ** * ** * ** **** * * * ** *** * += *(a + i) * *(b + i);
** * ** *** * ** ********** sum;
}

int * ******
{
* * * *** * * * * *** * *
*** * * **** ** ** c, n;

** * ** ** ** * **** * ** * ** //Enter number of * * in array
** ***** * *** ( c = 0 ; c * ** n ; c++ ) * ***** * * ** * ** * * ***** array A
* * ** * * * ** *** * * * * * ** *** * ** ** ** ** * * *
*** * * ** **** ( c = 0 ; c **** n ; c++ ) ** * * *** * * array B
** * ** ** ** * ** ***** * ** * * **** **** * * * ** ** ** ***

* *** *** * * * ***** ** * **** *** * *** * ****

* * *** *** ** 0;
}
最新回答 用戶: (-168 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include ** * * * **
double inner_product(double a[],double b[],int n)
{
* * ***** * ** * ** ** * i;
** * *** **** * ** * * * res = 0;
* * * * *** *********** ** * ** *
* * * * * ******* *** * ** * * ****** * ** *
* * ****** ** ****** *** * **** * * * * ********* **** a[i] * b[i];
* * * ** * * * *
* * * ** * *** *** ** res;
}
int main(void)
{
*** *** * * ***** ** * ******* * arrayA[100], arrayB[100];
* *** ***** ** * * * c, n;
******* ** *** ***** *** * ***** &n); //Enter number of elements in array
*** * * * * *** ( c = 0 ; c < n ; c++ ) **** ** ** * ** * * * * * array A
* ** **** *** ** **** * * *** *** * * * * * **** * * ***** * * * * *** ***
* * ** *** *** * ( c = 0 ; c < n ; c++ ) * * * *** ** * ** **** ** * array B
*** **** * ** * ** ** * * * ** **** * * ** * *** * * ** ** * ***
* * ** * * * ** ** *** *
* * *** ** * * * ** * * ** * * ***** ** ***** *** *
* *** ** * ***
*** *** * ** * * * 0;
}
最新回答 用戶: (323 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include ** * * * **
double ** * * ******* * * b[],int n)
{
* * *** *** * * * * m;m=0;
*** * * * ** * *** ( i = 0 ; i < n ; i++ )
** * *** ** *** *
* ** ** ** * **** ** ** ****** **** * ** ***
* * * ** * ***
* ** * ** *** * * ** m;
}


int *****
{
* ** * * * * * ** ****** *
** * * * ** ** c, n;

* * ** * * * ***** * * ** ***** *** * //Enter number of elements in array
* * ** **** ***** * ( c = 0 ; c < n ; c++ ) * ** * ** ** * ** *** * * array A
***** ** ** *** *** **** * * ** * ** ** *** ** ** * *** ** *
* * ** *** ** * * ( c = 0 ; c < n ; c++ ) * * *** * **** ** * * **** array B
** * * * * **** * * * ****** *** *** ** ** * * * *

*** * * * * * * **** ** * * ** ** *

* * * * * * * * * *** 0;
}
最新回答 用戶: (-168 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 喜歡 0 不喜歡
內容已隱藏
** * * ** * * * ***
double * * * *** *** b[],int n)
{
** ** * ** **** * *** YOUR CODE HERE*/
***** * * **** ** * * *** *** *
*** ** *** * ** * ** * * * * * * * **
** * ** ** **** ****** *** ** ** ** **** = sum + ** *

* * * * **** * *** * *****
** * ***** * ** *** * *** * sum;
*** *** *** **** * OF YOUR CODE*/
* * * * ** *** function should return a[0] * b[0] + a[1] * b[1] + ... + a[n-1] * b[n-1].
}

int *******
{
* **** * * * *** * * * *
** ** * * *** ***** c, n;

** **** * ***** * * * ***** * ** * *** * //Enter number of * * in array
* * **** * * ** ( c = 0 ; c * ** n ; c++ ) * * *** * * ****** * array A
** ****** * ******* * * ** ** * ***** * * * * ** ** **** ***** *
* ** * *** * ** * ( c = 0 ; c * * n ; c++ ) * * * ** * **** ** ** * array B
* ** * *** ** * * * ** *** ***** *** * **** * *** *

* ** *** * * *** * ** ** * * ***

** * * * * * 0;
}
最新回答 用戶: (-286 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.7.150
©2016-2025

相關問題

0 喜歡 0 不喜歡
50 回答
[練習] Coding (C) - 最新提問 12月 13, 2017 分類:Chapter 9: Functions | 用戶: semicolon (5.2k 分)
ID: 37278 - 從幾時開始: 2017-12-14 18:00 - 到幾時結束: 無限制
| 12.5k 瀏覽
0 喜歡 0 不喜歡
41 回答
[練習] Coding (C) - 最新提問 12月 14, 2017 分類:Chapter 9: Functions | 用戶: semicolon (5.2k 分)
ID: 37370 - 從幾時開始: 2017-12-14 18:00 - 到幾時結束: 無限制
| 9k 瀏覽
0 喜歡 0 不喜歡
70 回答
[練習] Coding (C) - 最新提問 12月 7, 2017 分類:Chapter 9: Functions | 用戶: semicolon (5.2k 分)
ID: 35783 - 從幾時開始: 2017-12-07 18:00 - 到幾時結束: 無限制
| 14.4k 瀏覽
12,783 問題
183,442 回答
172,219 留言
4,824 用戶