How to execute this using vector?
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
const int MAXCNT = 10; // Constant
float arr[MAXCNT], x; // Array, temp. variable
float array2[MAXCNT];
int i, cnt; // Index, quantity
cout << "Enter up to 10 numbers \n"
<< "(Quit with a letter):" << endl;
for (i = 0; i < MAXCNT && cin >> x; ++i)
arr[i] = x;
cnt = i;
// copying elements of an array to another
// array2 = arr
for (int index = 0; index < cnt; index++)
array2[index] = arr[index];
cout << "The given numbers:\n" << endl;
for (i = 0; i < cnt; ++i)
cout << setw(10) << arr[i];
cout << endl;
return 0;
}
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
const int MAXCNT = 10; // Constant
vector<float> arr;
vector<float> array2;
float x;
int i, cnt; // Index, quantity
cout << "Enter up to 10 numbers \n"<< "(Quit with a letter):" << endl;
for (i = 0; i < MAXCNT && cin >> x; ++i)
arr.push_back(x);
cnt = i;
// copying elements of an array to another
// array2 = arr
for (int index = 0; index < cnt; index++)
array2.push_back(arr[index]);
cout << "The given numbers:\n" << endl;
for (i = 0; i < cnt; ++i)
cout << setw(10) << arr[i];
cout << endl;
system("pause");
return 0;
}
Comments
Leave a comment