arithmetic progression c++
#include <iostream>
using namespace std;
int main() {
int firstTerm, commonDifference, n;
cout << "Enter the first term: ";
cin >> firstTerm;
cout << "Enter the common difference: ";
cin >> commonDifference;
cout << "Enter the number of terms: ";
cin >> n;
cout << "Arithmetic Progression: ";
for (int i = 0; i < n; i++) {
cout << firstTerm + i * commonDifference << " ";
}
return 0;
}
This C++ program calculates an arithmetic progression given the first term, common difference, and the number of terms inputted by the user. It uses a for
loop to iterate through the number of terms specified and calculates each term of the arithmetic progression using the formula ( \text{term} = \text{firstTerm} + i \times \text{commonDifference} ), where ( i ) represents the index of the term.