52 lines
1.4 KiB
C
52 lines
1.4 KiB
C
#include <stdio.h>
|
|
#define ONE 1
|
|
#define FOUR 4
|
|
#define ZERO 0
|
|
#define TWO 2
|
|
//---------------------------------------------------------------------------------------
|
|
// Exercise 2_6
|
|
// ------------
|
|
//
|
|
// General : The program performs the formula of the roots.
|
|
//
|
|
// Input : 3 numbers (a,b,c from ax^2+bx+c).
|
|
//
|
|
// Process : The program performs the formula of the roots.
|
|
//
|
|
// Output : 2 numbers (sign and result).
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programmer : Cohen Idan
|
|
// Student No : None
|
|
// Date : 19.09.2019
|
|
//---------------------------------------------------------------------------------------
|
|
void main(void)
|
|
{
|
|
short num_a,
|
|
num_b,
|
|
num_c,
|
|
delta,
|
|
sign = ONE,
|
|
result = ZERO;
|
|
|
|
printf("Enter a,b,c from ax^2+bx+c: ");
|
|
scanf("%hd%hd%hd", &num_a, &num_b, &num_c);
|
|
|
|
// Calculate delta
|
|
delta = (num_b * num_b) - (FOUR * num_a * num_c);
|
|
result = -num_b / TWO * num_a;
|
|
if (delta > ZERO)
|
|
{
|
|
sign = TWO;
|
|
result = ZERO;
|
|
}
|
|
if (delta < ZERO)
|
|
{
|
|
sign = ZERO;
|
|
result = ZERO;
|
|
}
|
|
|
|
printf("If you got sign '0' - not result\n\
|
|
If you got sign '1' - one result\n\
|
|
If you got sign '2' - two results:\nSign: %hd\nResult: %hd\n", sign, result);
|
|
} |