+ 1

All the even elements of the integer array K (n) are placed in the array L (n), and the odd ones in the array M (n). Calculate t

help!

2nd Nov 2017, 2:04 PM
Красавчик Том
Красавчик Том - avatar
9 Respuestas
+ 1
This is the code. It works. Example of input: 3 1 2 3 I hope this is what you wanted: #include <iostream> using namespace std; int main() { cout << "Enter number of values: " << flush; int n; cin >> n; //const int n = f; //Getting n value... cout << n << endl; int K[n]; int LP = 0; int MP = 0; cout << "Enter numbers: " << endl; //Initializing K array... for(int i = 0; i < n; i++){ int v; cin >> v; cout << v << endl; K[i] = v; } //Getting Size of L and M arrays... for(int i = 0; i < n; i++){ if(K[i] % 2 == 0){ LP += 1; } else { MP += 1; } } int L[LP]; int M[MP]; LP = 0; MP = 0; for(int i = 0; i < n; i++){ if(K[i] % 2 == 0){ L[LP] = K[i]; LP += 1; } else { M[MP] = K[i]; MP += 1; } } cout << "K Values: " << endl; for(int i = 0; i < n; i++){ cout << K[i] << endl; } cout << "L values: " << endl; for(int i = 0; i < LP; i++){ cout << L[i] << endl; } cout << "M values: " << endl; for(int i = 0; i < MP; i++){ cout << M[i] << endl; } return 0; }
2nd Nov 2017, 7:54 PM
Rain
Rain - avatar
+ 1
thx. And how to do it? All the even elements of the integer array K (n) are placed in the array L (n), and the odd ones in the array M (n).
2nd Nov 2017, 2:20 PM
Красавчик Том
Красавчик Том - avatar
+ 1
Thank you so much
2nd Nov 2017, 7:35 PM
Красавчик Том
Красавчик Том - avatar
0
I need to put even elements of one array in another array and put the odd elements of the array in the third array.
2nd Nov 2017, 2:27 PM
Красавчик Том
Красавчик Том - avatar
- 1
Calculate the number of both.)
2nd Nov 2017, 2:14 PM
Красавчик Том
Красавчик Том - avatar