/*
 * assign : hw3, part 1
 */
#include <stdio.h>

void main() {

	/* initization.. 
	   sum : hold the sum of factors
	   num_perf: count the number of perfect numbers
	 */
	int sum =0, i, j, num_perf=0;

	/* 1 cannot be a perfect number.. thus start from 2
	   loop while num_perf is less than 4 
	       ( stops when it founds 4 perf_num)
	 */
	for ( i = 2; num_perf < 4; i ++ )
	{
		sum = 0;
		
		/* find factors & add to the sum*/
		for ( j = 1; j < i ; j++ ) {
			/* test if j is a factor of i*/
			if ( i % j == 0 ) {
				sum += j;
			}
		}

		/* if perfect nubmer, print out the number
		   and increase the counter */
		if ( i == sum ) {
			printf ( "perfect number = %d\n", i);
			num_perf ++;
		}
	}
}
		

	
	
/*
 * assign : homework #3, part 2
 * 
 * answer : x = 5 after the statement..

int x = 8, y = 2, w = 6, z = 1; 
if ( y < x ) 
	z++; 
if ( z == y ) 
	x = --w; 
else 
	x = w--;

y < x is true, thus, z ++;
z becomes 2

since y == z, 2 == 2
thus x = --w;
since it's prefix, w becomes 5 and x becomes 5
*/





/*
 * assign : hw#3 part 3
 */

#include <stdio.h>
void main()
{
	int a = 11, b = 5 , c = 3 , d = 0, e = -4 ;
	float f;
	int i;

	/* prints the result of the first expression*/
	printf ("result 1 : %f\n", f = ((float) a)/((float) b) +c);

	/* reinitize the variables..*/
	a = 11; b = 5; c = 3;d = 0; e = -4 ;
	
	/* prints the result fo the second expression */
    printf ("result 2: %d\n", i = (c || b && d));

	/* reinitize the variables..*/
	a = 11; b = 5; c = 3;d = 0; e = -4 ;

	/* printd the result of the third expression */
	printf ("result 3: %d\n", i = (d == (--a % b)));

}

/* output of the program.
 result 1 : 5.200000
 result 2: 1
 result 3: 1
 
 thus the result of the first expression is 5.2000
 the result of the second expression is 1
 the result of the third expression is 1
*/
