ElenaMednikova

Untitled

Oct 30th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. 4.1
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. setlocale(0, "");
  7. int n, sum=0, a;
  8. cin >> n;
  9. if (n>0)
  10. {
  11. for (int i = 0; i <= n; i++)
  12. {
  13. a = i*i;
  14. sum += a;
  15. }
  16. cout << sum;
  17. system("pause");
  18. }
  19. if (n<0)
  20. {
  21. cout<<"Bang bang"<<endl;
  22. }
  23. return 0;
  24. }
  25. 4.2
  26. #include <iostream>
  27. using namespace std;
  28. int main()
  29. {
  30. setlocale(0, "");
  31. int n, sum=0;
  32. cin >> n;
  33. if (n>0)
  34. {
  35. for (int i = 0; i <= n)
  36. {
  37. sum+=i;
  38. i+=2;
  39. }
  40. cout << sum;
  41. system("pause");
  42. }
  43. else if(n<0)
  44. for(int i=-1; i<=0)
  45. {
  46. sum+=i;
  47. i-=2;
  48. }
  49.  
  50. return 0;
  51. }
Add Comment
Please, Sign In to add comment