/* Introduction
to program:
Program
- permbad.c.
Example
of how not to permute three numbers.
Francis
O'Donovan 2-2-98. */
/* Files to be included. */
#include <stdio.h>
/* ********************************************** */
/* Function: main(). */
main()
{
/*
Declare functions. */
void Permute();
/* Initialize variables. */
int x, y, z; /* The three
numbers to be used. */
/*
Print introduction. */
printf( "Program: permbad.c.\n" );
printf(
"Example of how not to permute three numbers.\n" );
printf(
"Francis O'Donovan 2-2-98.\n\n" );
/* Get user to input numbers. */
printf( "Please type in three numbers, x, y, and z:\n"
);
scanf(
"%d", &x );
scanf(
"%d", &y );
scanf(
"%d", &z );
/*
Call Permute(). */
Permute( x, y, z );
/* Output the three numbers. */
printf( "x = %d, y = %d, z = %d.\n", x, y, z );
}
/* ************************************************ */
/* Function:
Permute().
Purpose:
Tries to permute three integers.
Arguements:
Three ints.
Returns:
void.
*/
void Permute( x, y, z)
int x, y, z;
{
/*
Initialise variables. */
int
temp; /* temporary holder.
*/
/* Attempt to permute the numbers. */
temp = x;
x =
y;
y =
z;
z =
temp;
}
/* Comment:
This
program will not permute the three numbers, because Permute
only
permutes the local variables x, y, and z in Permute. It does
not
affect the variables x, y, and z in main, so they stay the same.
*/
© Francis O'Donovan
1999.