+ 1

How to multiple all members of the array?

16th Apr 2018, 3:25 PM
Cлaвeн Ђервида
Cлaвeн Ђервида - avatar
6 Réponses
+ 5
#include <iostream> using namespace std; int main() { int a[]={1,2,3,4}; int multiply = 1; for(int x : a) multiply*=x; cout << multiply; return 0; }
19th Apr 2018, 7:25 PM
Tanay
Tanay - avatar
+ 4
How about this? int a[] = { 1, 2, 3 }; for(auto &i : a) ++i;
16th Apr 2018, 3:44 PM
Disvolviĝo;
Disvolviĝo; - avatar
0
I think you mean multiply: int main() { int arr[] = {2, 3, 4}; int total = 1; for (int num: arr) { total *= num; } return 0; }
16th Apr 2018, 3:33 PM
TurtleShell
TurtleShell - avatar
0
sorry
16th Apr 2018, 3:34 PM
Cлaвeн Ђервида
Cлaвeн Ђервида - avatar
0
I try to do this if a[]={1,2,3} to make members a[]++ and then members is 2,3,4
16th Apr 2018, 3:35 PM
Cлaвeн Ђервида
Cлaвeн Ђервида - avatar
0
how to that
16th Apr 2018, 3:35 PM
Cлaвeн Ђервида
Cлaвeн Ђервида - avatar