HP C A.06.05 Reference Manual
Statements
for
Chapter 6 163
#define SIZE 10
int main(void)
{
int n, m, n_total, m_total, perm, i, j, mid, count;
printf("Enter the numbers for the permutation (n things ");
printf("taken m at a time)\nseparated by a space: ");
scanf("%d %d", &n, &m);
n_total = m_total = 1;
for (i = n; i > 0; i--) /* compute n! */
n_total *= i;
for (i = n - m; i > 0; i--) /* compute (n-m)! */
m_total *= i;
perm = n_total/m_total;
printf("P(%d,%d) = %d\n\n", n, m, perm);
/* This series of for loops prints a pattern of "Z's" and shows
* how loops can be nested and how you can either increment or
* decrement your loop variable. The loops also show the proper
* placement of curly braces to indicate that the outer loops
* have multiple statements.
*/
printf("Now, print the pattern three times:\n\n");
mid = SIZE/2;
/* controls how many times pattern is printed */
for (count = 0; count < 3; count++)
{
for (j = 0; j < mid; j++)
{
/* loop for printing an individual line */
for (i = 0; i < SIZE; i++)
if (i < mid - j || i > mid + j)
printf(" ");
else
printf("Z");
printf("\n");
}
for (j = mid; j >= 0; j--)
{
for (i = 0; i <= SIZE; i++)