Instead of while, use do...while. That way, the loop will always run at least once.
num_of_triangles = 0;
do {
printf("Number of triangles (must be greater than 2) = ");
scanf("%d", &num_of_triangles);
while (getchar() != '\n'); // this flushes the input buffer
} while (num_of_triangles < 3);
Also, don't fflush(stdin), as that's undefined behavior.
EDIT:
It seems that Visual Studio allows fflush(stdin). From MSDN:
The fflush function flushes a stream. If the file associated with
stream is open for output, fflush writes to that file the contents of
the buffer associated with the stream. If the stream is open for
input, fflush clears the contents of the buffer. fflush negates the
effect of any prior call to ungetc against stream. Also, fflush(NULL)
flushes all streams opened for output. The stream remains open after
the call. fflush has no effect on an unbuffered stream.
In general however, this behavior shouldn't be depended on. Doing something more portable like the above code is preferable.
fflush(stdin)is undefined behaviour.