Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- short int n, d, k, an;
- bool isCorrect = false;
- do
- {
- cout <<"\This program displays sequence elements\n";
- cout << "\nEnter a value of k and d:\n";
- cin >> k;
- cin >> d;
- isCorrect = true;
- if ((k <= 0) || (d <= 0 ))
- {
- isCorrect = false;
- cout << "\nEnter a value greater than zero\n";
- }
- } while (isCorrect);
- an = 0;
- n = 1;
- while (n <= k)
- {
- an += an + n * d;
- n++;
- printf(an);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement