First Upload

This commit is contained in:
2022-02-25 15:33:16 +02:00
commit 0c74d10f0d
295 changed files with 74784 additions and 0 deletions

BIN
3/ex1 Normal file

Binary file not shown.

49
3/ex1.c Normal file
View File

@@ -0,0 +1,49 @@
#include <stdio.h>
#define SUM(a,b) a + b
#define DIFFERENCE(a,b) a - b
#define MULTIPLICATION(a,b) a * b
#define DIVIDE(a,b) a / b
//---------------------------------------------------------------------------------------
// Exercise 1
// ----------
//
// General : The program do math with two numbers and one operator.
//
// Input : 2 numbers (results), 1 char.
//
// Process : The program checks the operator and process math on 2 numbers.
//
// Output : 1 number.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 19.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
float num1,
num2,
result;
char opr;
printf("Enter mathematical expression (a + b): ");
scanf("%f %c %f", &num1, &opr, &num2);
switch (opr)
{
case '-':
result = DIFFERENCE(num1, num2);
break;
case '/':
result = DIVIDE(num1, num2);
break;
case '*':
result = MULTIPLICATION(num1, num2);
break;
default:
result = SUM(num1, num2);
break;
}
printf("The result: %f\n", result);
}

56
3/ex2.c Normal file
View File

@@ -0,0 +1,56 @@
#include <stdio.h>
#define BOOLEAN unsigned short
#define TRUE 1
#define FALSE 0
#define ONE_HUNDRED_SIXTY 160
#define ONE_HUNDRED_FIFTY 150
#define FORTY 40
#define SIXTY 60
#define ZERO 0
#define MAX(a,b) a > b ? a : b
#define MIN(a,b) a < b ? a : b
//---------------------------------------------------------------------------------------
// Exercise 2
// ----------
//
// General : The program checks for the logical results of a championship game in
// the basket ball.
//
// Input : 2 numbers (results).
//
// Process : The program checks for the logical results by conditions.
//
// Output : '1' if is it True, '0' is false.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 19.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
unsigned short result1,
result2,
max_result,
min_result,
difference;
BOOLEAN answer = FALSE;
printf("Enter 2 numbers: ");
scanf("%hu%hu", &result1, &result2);
max_result = MAX(result1, result2);
min_result = MIN(result1, result2);
difference = max_result - min_result;
if ((max_result <= ONE_HUNDRED_FIFTY) &&
(min_result >= FORTY) &&
(difference <= SIXTY) &&
(difference > ZERO))
{
answer = TRUE;
}
printf("The answer: %hu\n", answer);
}

52
3/ex2_6.c Normal file
View File

@@ -0,0 +1,52 @@
#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);
}

BIN
3/ex2_7 Normal file

Binary file not shown.

44
3/ex2_7.c Normal file
View File

@@ -0,0 +1,44 @@
#include <stdio.h>
#define ONE 1
#define TWO 2
//---------------------------------------------------------------------------------------
// Exercise 2_7
// ------------
//
// General : The program change letters by one depends on situation.
//
// Input : 2 letters.
//
// Process : The program checks if the first letter is before the second in
// the ABC and acts accordingly.
//
// Output : '1' if is it True, '0' is false.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 19.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
char a,
b,
final_a,
final_b,
opr = '+';
printf("Enter 2 chars: ");
scanf("%c%c", &a, &b);
final_a = a + ONE;
final_b = b - ONE;
if (a > b)
{
final_a -= TWO;
final_b += TWO;
opr = '-';
}
printf("%c %c %c\n", final_a, opr, final_b);
}

BIN
3/ex3 Normal file

Binary file not shown.

46
3/ex3.c Normal file
View File

@@ -0,0 +1,46 @@
#include <stdio.h>
#define TEN_THOUSAND 10000
#define ONE_HUNDRED 100
//---------------------------------------------------------------------------------------
// Exercise 3
// ----------
//
// General : The program print the date as a sentence.
//
// Input : 1 number.
//
// Process : The program take the year, month and day from the input and put in
// a sentence.
//
// Output : A sentence.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 19.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
int date,
temp_date;
short day,
month,
year;
printf("Enter date: ");
scanf("%d", &date);
temp_date = date;
year = temp_date - (temp_date / TEN_THOUSAND) * TEN_THOUSAND;
temp_date /= TEN_THOUSAND;
month = temp_date - (temp_date / ONE_HUNDRED) * ONE_HUNDRED;
temp_date /= ONE_HUNDRED;
day = temp_date;
printf("The year is %hd, the month is %hd, and the day is %hd\n", year, month, day);
}

BIN
3/ex4 Normal file

Binary file not shown.

44
3/ex4.c Normal file
View File

@@ -0,0 +1,44 @@
#include <stdio.h>
#define TEN_THOUSAND 10000
#define ONE_HUNDRED 100
#define MONTHS 12
#define THREE 3
//---------------------------------------------------------------------------------------
// Exercise 4
// ----------
//
// General : The program print the period by month in date.
//
// Input : 1 number.
//
// Process : The program take the month, and check which belongs to period.
//
// Output : A sentence.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 19.09.2019
//---------------------------------------------------------------------------------------
void main(void)
{
int date,
temp_date;
short month;
printf("Enter date: ");
scanf("%d", &date);
temp_date = date / TEN_THOUSAND;
month = temp_date - (temp_date / ONE_HUNDRED) * ONE_HUNDRED;
month %= MONTHS;
month /= THREE;
printf("If you got '0' this WINTER \n\
If you got '1' this SPRING \n\
If you got '2' this SUMMER \n\
If you got '3' this AUTUMN \n\
You got: %hd\n", month);
}

55
3/part2.c Normal file
View File

@@ -0,0 +1,55 @@
#define ABS(x) x * (((2 * x) + 1) % 2)
#define MAX(x, y) ((x+y) + ABS(x-y))/2
#define TWO 2
#define THREE 3
#define ZERO 0
// Part 2 exercise 2
void main(void)
{
short x_king,
y_king,
x_zariah,
y_zariah,
answer;
// If answer == '0' is TRUE, else is FALSE
if ((x_king - x_zariah) * (y_king - y_zariah) == ZERO){}
}
// Part 2 exercise 3
void main(void)
{
short x_king,
y_king,
x_runner,
y_runner,
answer;
// If answer == '0' is TRUE, else is FALSE
if (ABS(x_king - x_runner) - ABS(y_king - y_runner) == ZERO){}
}
// Part 2 exercise 4
void main(void)
{
short x_king,
y_king,
x_horseman,
y_horseman,
answer;
// If answer == '0' is TRUE, else is FALSE
if (ABS(x_king - x_horseman) + ABS(y_king - y_horseman) - THREE == ZERO){}
}
// Part 2 exercise 5
void main(void)
{
short a,
b,
answer;
answer = ((a+b) + ABS(a-b))/TWO;
}