/*
This program demonstrates operator precedence with a variety of examples.
G.C. Rutledge
September 2002
*/

#include <stdio.h>

int main(void)
{
	float answerfloat;
	int answer,f,g,x,y,z=0;

/* The first five groups of statements print out the results of
	five simple mathematical equations. */

	printf("4+5*3 =\n");
	answer=4+5*3;
	printf("%d\n", answer);

	printf("(4+5)*3 =\n");
	answer=(4+5)*3;
	printf("%d\n", answer);

	printf("4*3/9 =\n");
	answer=4*3/9;
	printf("%d\n", answer);

	printf("3/9*4 =\n");
	answer=3/9*4;
	printf("%d\n", answer);

        printf("3.0/9.0*4.0 = \n");
	answerfloat = 3.0/9.0*4.0;
	printf("%f\n",answerfloat);

	printf("3*3%%2+1 =\n");
	answer=3*3%2+1;
	printf("%d\n\n", answer);
	
/* The following two groups of statements help describe the
	important '=' operator. */

	printf("f+=f=5, f is now equal to:\n");
	f+=f=5;
	printf("%d\n", f);

	printf("g*=g=5, g is now equal to:\n");
	g*=g=5;
	printf("%d\n\n", g);

/* The final group of statements demonstrates the importance
	of caution when using the '++' operator. */

	printf("Be cautious with your ++ operator, especially in assignments!\n");
	printf("We start with z=0, then:\nx=++z\ny=z++\n\nAnd what do we have now?\n");
	x=++z;
	y=z++;	
	printf("x=%d, y=%d, z=%d\n\n\n",x,y,z);

return(0);
}

