So this array has a set of values already assign to it.
Is there a way to print out the array that was assigned to it and also add them all together in one FOR loop?
Line 16 FOR loop shows that I do know how to add the arrays. I am just wondering if I can do it all in just one.
Thank you
ps This is not homework, it is from C++ without fear exercise. Just trying to learn extra stuff over spring break.
#include <iostream>
#include <cmath>
usingnamespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int array[6]={10,22,13,99,4,5};
for (int i=0; i<6; i++){
cout<<array[i]<<endl;
array[i]=array[i]+array[i+1];
cout<<array[i]<<endl;
cout<<"\nThe Value of i: "<<i<<endl;
}
//for (int i=1; i<6; i++){
// array[i]+=array[i-1];
// cout<<array[i]<<endl;
// }
return 0;
}