C++ Program to Print an Arithmetic Progression.
If the first element of an A.P. is a, and the common difference is d, then the n-th element of that A.P. is a + (n - 1) * d. Write a program to print the first ten digits of an A.P. Obtain a and d from the user.
#include <iostream> using namespace std; int main() { int a, d; cout << "Enter a: "; cin >> a; cout << "Enter d: "; cin >> d; int counter = 0; while (counter++ < 10) { cout << a + (counter - 1) * d; cout << endl; } return 0; }
My C/C++ Videos on Youtube
Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.
This Blog Post/Article "Program to Print an A.P." by Parveen (Hoven) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Updated on 2020-02-07. Published on: 2015-12-08