+ 1
C++ arrays and array parameter - BUG!
This code has a bug! (Bugs on lines 4 and 21 according to online compiler C++ shell). Purpose of this program: I am trying to cin inside an array and pass in that array to another function to do some multiplication and then print out the values. . Please take a look at this code. #include <iostream> using namespace std; void tripler (int n[]){ for (int i = 0; i < 3; i++){ n[i] = n[i] * i; cout << n[i]; } } int main (){ int a[3]; for (int i = 0; i < 3; i++){ cin >> a[i]; int size = 0; size += i; tripler (a[size]); } return 0; } c++ shell link: cpp.sh/96ohq7
2 Respuestas
+ 1
#include <iostream>
using namespace std;
void tripler (int n[]){
for (int j = 1; j <= 3; j++){
for (int i = 0; i < 3; i++){
n[i] *= j;
cout << n[i]<<",";
}
cout<<endl;
}
}
int main (){
int a[3];
for (int i = 0; i < 3; i++){
cin >> a[i];
}
tripler (a);
return 0;
}
+ 1
Nice one my friend! :)