I'm a beginner in programming and I'm having trouble with the following problem:
Make a program that calculates and prints all triangular numbers smaller than 1000.
A triangular number is a natural number that can be represented in the triangular number
equilateral triangle shape. To find the nth number triangular from the previous just add n units. THE triangular numbers (sequence A000217 in the OEIS), beginning with the 0th term, is:
0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
My code looks like this:
#include<iostream>
using namespace std;
int main(){
int b, a;
for (a = 0, b = 0; b < 1000;a++){
b = (a + 1) + b;
cout << b << endl;
}
return 0;
}
The only problem is that when I compile, it goes to 1035.