Advertisement
Programmin-in-Python

C++ Program to print Arithmetic Progression(AP)

Jan 10th, 2022
1,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int a, n, d, term;
  6.  
  7.     cout << "Enter the First Term (a) : ";
  8.     cin >> a;
  9.     cout << "Enter the Common Difference (d) : ";
  10.     cin >> d;
  11.     cout << "Enter the Number of terms (n) : ";
  12.     cin >> n;
  13.  
  14.     cout << "The Arithmetic Progression is :-" << endl;
  15.  
  16.     term = a;
  17.     cout << term << endl;
  18.  
  19.     for (int i=1; i<n; i++){
  20.         term += d;
  21.         cout << term << endl;
  22.     }
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement