Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(int argc, char* argv[])
  5.  
  6. {
  7. //question 1 - What are four ways to add 1 to an int.
  8. int x;
  9. x = 0;
  10.  
  11. x++;
  12. ++x;
  13. x = x + 1;
  14. x += 1;
  15.  
  16. cout << "X is " << x << endl;
  17.  
  18. //question 2 - sum all the odd numbers between 0 and 100
  19. int sum;
  20. sum = 0;
  21.  
  22. for (int i = 1; 1 <= 100; i++)
  23. {
  24. if (i % 2 != 0)
  25. sum = sum + i;
  26. }
  27.  
  28. cout << "Sum of odd numbers is " << sum;
  29.  
  30. return 0;
  31. cin.get();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement