Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. /* Joel Bares
  2.  CIS 22A Winter 2017
  3.  Assignment I
  4.  Problem I1
  5.  
  6.  This Program
  7.  displays usage of arrays
  8.  by using for loops to
  9.  calculate a sum
  10.  for these numbers
  11. */
  12.  
  13.  
  14.  
  15. #include <iostream>
  16.  
  17. using namespace std;
  18.  
  19.  
  20. int main()
  21. {
  22.     int i[4];
  23.     i[0] = 4;
  24.     i[1] = 6;
  25.     i[2] = 9;
  26.     i[3] = 12;
  27.     int sum = 0;
  28.    
  29.     for(int count = 0; count < 4; count++)
  30.     {
  31.         sum = sum + i[count];
  32.     }
  33.    
  34.     for(int count2 = 0; count2 < 4; count2++)
  35.     {
  36.         cout << i[count2];
  37.         if(count2 <= 2)
  38.         {
  39.             cout << " + ";
  40.         }
  41.        
  42.         if(count2 == 3)
  43.         {
  44.             cout << " = " << sum << endl;
  45.         }
  46.     }
  47. }
  48.  
  49.  
  50. /* EXECUTION RESULTS:
  51.  
  52.  4 + 6 + 9 + 12 = 31
  53.  Program ended with exit code: 0
  54.  
  55. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement