[問題] 賦值給動態一維陣列
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++2008
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
兩個長度n儲存整數的array a[i],b[i]
返回c[i]=a[i]*b[i],i=0,1...,n-1
餵入的資料(Input):
由鍵盤輸入n值,再分別輸入array a[i],b[i]
預期的正確結果(Expected Output):
返回c[i]=a[i]*b[i],i=0,1...,n-1
錯誤結果(Wrong Output):
鍵盤輸入的a[i],b[i]好像沒成功存入
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std;
int main()
{
int *a=NULL,*b=NULL,*c=NULL;
int m,i;
cout<<"Please input the dimension:";
cin>>m;
a=new int[m];
b=new int[m];
c=new int[m];
cout<<"Please input the vector:";
for(i=0;i<m;i++) cin>>a[i];
cout<<"Please input the other vector:";
for(i=0;i<m;i++) cin>>b[i];
for(i=0;i<m;i++)
c[i]=a[i]*b[i];
cout<<c[i];
return 0;
}
補充說明(Supplement):
--
肝不好 ▁▁ ● ◤ 肝若好
人生是黑白的 ▏ ◤ 考卷是空白的
▏ ◤ 、 ﹐
● ●b 囧 ▎ ●> ● ◤ ▌ ﹍﹍ 0 ▊囧> 幹...
▲ ■┘ ■ ▎ ■ █◤ ▌ ㄏ▋ ︶■
〈﹀ ∥ ▁▁∥ ▎ ﹀〉◤ ▋ ▊ 〈\ ψcockroach727
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.245.27
→
10/12 23:42, , 1F
10/12 23:42, 1F
→
10/12 23:42, , 2F
10/12 23:42, 2F
→
10/12 23:42, , 3F
10/12 23:42, 3F
→
10/12 23:44, , 4F
10/12 23:44, 4F
→
10/12 23:45, , 5F
10/12 23:45, 5F
→
10/12 23:47, , 6F
10/12 23:47, 6F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章