Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. short int n, d, k, an;
  6. bool isCorrect = false;
  7. do
  8. {
  9. cout <<"\This program displays sequence elements\n";
  10. cout << "\nEnter a value of k and d:\n";
  11. cin >> k;
  12. cin >> d;
  13. isCorrect = true;
  14. if ((k <= 0) || (d <= 0 ))
  15. {
  16. isCorrect = false;
  17. cout << "\nEnter a value greater than zero\n";
  18. }
  19. } while (isCorrect);
  20. an = 0;
  21. n = 1;
  22. while (n <= k)
  23. {
  24. an += an + n * d;
  25. n++;
  26. printf(an);
  27. }
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement