+ 1

how to cout index of the number multiply 3 from array a

#include <iostream> #include <time.h> #include <stdlib.h> using namespace std; int main() { setlocale(LC_ALL, "RUSSIAN"); int a[15], b[15], i, j = 0; cout << "Array: " << endl; for (i = 0; i < 15; i++) cin >> a[i]; for (i = 0; i < 15; i++) if ((a[i] % 4) == 0) { b[j] = a[i]; j++; }; cout << "Array : " << endl; for (i = 0; i < j; i++) cout << b[i] << endl; return 0; }

5th Dec 2020, 12:07 AM
storix
2 Answers
+ 2
You don't need another array. Use your original array and use if(a[i] % 3 == 0) to get indexs that are the multiple of 3. And cout << a[i];
5th Dec 2020, 1:02 AM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar
+ 1
storix Are you looking for a multiple of 3 in array <a> or only in array <b>? cause I see you are filtering only multiples of 4 from array <a> into array <b>. I confirmed this in your previous thread, but you did not respond ... https://www.sololearn.com/Discuss/2607645/?ref=app
5th Dec 2020, 2:54 AM
Ipang