#include <stdio.h><p>unsigned integer = 0;<p>unsigned int i = 0;<p>int main (char argc, char* argv[]) {<p><pre><code> while (i<1000) {
integer = integer + i;
i = i + 1;
printf("%u\n", integer);
}</code></pre>
};<p>Feel free to tell me ways to improve this.
The numbers generated by your program are called the triangular numbers:<p><a href="https://oeis.org/A000217" rel="nofollow">https://oeis.org/A000217</a><p>This is because of the relationship between the triangular numbers and the summation formula for integers.<p>Quite a lot is known about these and you can read references to a lot of it on that OEIS page (although some of it is kind of terse and assumes certain kinds of mathematical background). One thing you'll see there is a simple formula for computing these directly rather than by these repeated additions.<p>The primality issue is discussed at, for example,<p><a href="https://math.stackexchange.com/questions/1012320/how-many-prime-numbers-are-also-triangular-numbers" rel="nofollow">https://math.stackexchange.com/questions/1012320/how-many-pr...</a><p>If you ever write a program that generates a particular sequence and you want to know whether that sequence has already been studied in mathematics, OEIS has a <i>great</i> search engine tool which lets you search for specific integer sequences just by entering their terms. The results will show you huge amounts of detail about what mathematicians have already discussed and discovered about that sequence, possibly including other ways of generating it, or other sequences or formulas that are related to it somehow.<p>Edit: I feel it would be more idiomatic in C to write the main() function as something like<p><pre><code> int main(char argc, char* argv[]) {
for (i = 0; i < 1000; i++) {
integer += i;
printf("%u\n", integer);
}
};
</code></pre>
or, if you do want to use the while loop, to at least write "i++;" instead of "i = i + 1".<p>In modern C practice it's also more usual to declare most variables inside of the specific function that uses them, rather than as global variables outside of any function.