Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Joel Bares
- CIS 22A Winter 2017
- Assignment I
- Problem I1
- This Program
- displays usage of arrays
- by using for loops to
- calculate a sum
- for these numbers
- */
- #include <iostream>
- using namespace std;
- int main()
- {
- int i[4];
- i[0] = 4;
- i[1] = 6;
- i[2] = 9;
- i[3] = 12;
- int sum = 0;
- for(int count = 0; count < 4; count++)
- {
- sum = sum + i[count];
- }
- for(int count2 = 0; count2 < 4; count2++)
- {
- cout << i[count2];
- if(count2 <= 2)
- {
- cout << " + ";
- }
- if(count2 == 3)
- {
- cout << " = " << sum << endl;
- }
- }
- }
- /* EXECUTION RESULTS:
- 4 + 6 + 9 + 12 = 31
- Program ended with exit code: 0
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement