/*
 * assign : hw4, part 1
 */

#include <stdio.h>

void main()
{
	/* (i) first, takes the two integers X and Y as inputs 
	   from the user via scanf;
	 */
	int x, y, z;
	
	
	printf ("Enter x: ");
	scanf ("%d", &x);

	printf ("Enter y: ");
	scanf ("%d", &y);

	/* (ii) second, it uses a single line expression 
	   to compute the value of Z given by: 
	   Z = maximum of X and Y when: X > 0 and Y > 0. 
	   If either X or Y is not positive, Z = 1 
	 */

	 z = ( x>0 && y>0 ) ? ((x>y) ? x:y ) :1;

	 /* (iii) Third, the program must print the following: 
	    The value of Z is equal to ? 
		where "?" is replaced by the actual integer value of Z. 
	  */
	 printf ("The value of Z is equal to %d\n", z);
}
	 





/*
 * assign: hw4 part 2
 */

#include <stdio.h>
#include <math.h>   /* for sqrt() function */

void main(void)
{
	float a, b, c;
	float det;

	/* getting usr input */
	printf ("quadratic equation solver.\n");
	printf (" a x^2 + b x + c = 0\n");
	printf ("Please enter the followings\n");
	printf ("a = ");
	scanf ("%f", &a);

	printf ("b = ");
	scanf ("%f", &b);

	printf ("c = ");
	scanf ("%f", &c);


	/* calculating determent */
	det = b * b - 4 * a * c ;

	/* if det < 0, no solution */
	if ( det < 0 ) {
		printf ("No Solution\n");
	}
	
	/* if det == 0, one solution */
	if ( det == 0 ) {
		printf ("solution : %f\n", - b / ( 2 * a) );
	}

	/* if det > 0, two solutions */
	if ( det > 0 ) {
		printf ("solution 1 : %f\n", ( - b + sqrt (det) ) / ( 2 * a));
		printf ("solution 2 : %f\n", ( - b - sqrt (det) ) / ( 2 * a));
	}

	return;
}
