0
How its works,please help me!
#include <iostream> using namespace std; int main() { int myArr[4]; int x,y; int total=0; cin >> y; for(int x=0; x<=3; x++) { myArr[x] = y; cout << x << ": " << myArr[x] << endl; total = total + myArr[x]; cout << total; } return 0; } //inputs are 1 //outputs : 0 : 1 11 : 2 22 : 3 33 : 4 4
3 Respuestas
+ 1
cin >> y; //taking input to y, ex: 1
for(int x=0; x<=3; x++) {
myArr[x] = y; //every array element, you are assigning y => 1
cout << x << ": " << myArr[x]<<" : " ;
total = total + myArr[x];
cout << total<<endl;
Here total is, sum of array elements, in each iteration, you are displaying...
X : myArr[x] : total
0 1 1
1 1 2
2 1 3
3 1 4
Check this by removing endl and add it after total as I given above... I think, You are confusing with that only,.
In your code total displaying in next line, with other results without a separating... So add spaces for clear understanding, results...
0
Where is your confusion in this program...?
Which part you not understanding...
0
Explain full programme, because the output of this code is confused me.