我的读取不了数,求指点
1条回答 默认 最新
- threenewbee 2020-03-24 20:02关注
int n = 0; int * a = new int[10]; for (int i = 0; i < 10; i++) { int x; cin >> x; if (x % 2 == 1) a[n++] = x; } for (int i = 0; i < n; i++) cout << a[i] << endl; delete[] a;
解决 无用评论 打赏 举报
int n = 0;
int * a = new int[10];
for (int i = 0; i < 10; i++)
{
int x;
cin >> x;
if (x % 2 == 1) a[n++] = x;
}
for (int i = 0; i < n; i++) cout << a[i] << endl;
delete[] a;