Printing integers from 1 to 12 demonstrating the while loop in C programming
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: none
To do: Printing integers from 1 to 12 demonstrating the while loop in C programming
To show: How to use the while statement to print a range of integers in C programming
// Demonstrates a simple while statement
#include <stdio.h>
int main(void)
{
int calculate;
// print the integers from 1 to 12, set the initial value...
calculate = 1;
// set the while condition...
while(calculate <= 12)
{
// display...
printf("%d ", calculate);
// increment by 1, then repeat
calculate++;
}
printf("\n");
return 0;
}
Output example:
1 2 3 4 5 6 7 8 9 10 11 12
Press any key to continue . . .