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
6/IdanLib Normal file

Binary file not shown.

1190
6/IdanLib.h Normal file

File diff suppressed because it is too large Load Diff

BIN
6/PDFs/ex1.c.pdf Normal file

Binary file not shown.

BIN
6/PDFs/ex2.c.pdf Normal file

Binary file not shown.

BIN
6/PDFs/ex3.c.pdf Normal file

Binary file not shown.

BIN
6/PDFs/ex4.c.pdf Normal file

Binary file not shown.

BIN
6/PDFs/ex5.c.pdf Normal file

Binary file not shown.

BIN
6/PDFs/ex6.c.pdf Normal file

Binary file not shown.

BIN
6/ex1 Normal file

Binary file not shown.

74
6/ex1.c Normal file
View File

@@ -0,0 +1,74 @@
#include <stdio.h>
#define N 5
#define S 5
#define BOOLEAN unsigned short
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define ONE 1
//---------------------------------------------------------------------------------------
// SumInArray
// ----------
//
// General : Checks if there are two numbers whose sum is equal to
// the number entered as "sum".
//
// Parameters :
// array[] - array (int)
// size - array size (unsigned int)
// sum - The amount required (int)
//
// Return value : Counter (int).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : 211675038
// Date : 21.10.2019
//---------------------------------------------------------------------------------------
BOOLEAN SumInArray(int array[], unsigned int size, double sum)
{
BOOLEAN answer = FALSE;
unsigned int temp_size = size,
count;
double temp_sum;
for (count = ZERO; count < temp_size && !answer;)
{
temp_sum = array[count] + array[temp_size];
answer = (temp_sum == sum) ? TRUE : FALSE;
count += (temp_sum < sum) ? ONE : ZERO;
temp_size -= (temp_sum > sum) ? ONE : ZERO;
}
return (answer);
}
//---------------------------------------------------------------------------------------
// Exercise 1
// ----------
//
// General : The program checks whether the required sum of two numbers
// is in an ordered array.
//
// Input : None.
//
// Process : Uses a function called "SumInArray".
//
// Output : If the required sum of two numbers is found in an ordered array (BOOLEAN).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : 211675038
// Date : 23.10.2019
//---------------------------------------------------------------------------------------
void main(void)
{
int sort_numbers[N] = {1,2,3,4,5};
BOOLEAN answer = FALSE;
answer = SumInArray(sort_numbers, N, S);
printf("Answer: %hu\n", answer);
}

BIN
6/ex2 Normal file

Binary file not shown.

93
6/ex2.c Normal file
View File

@@ -0,0 +1,93 @@
#include <stdio.h>
#define N 30
#define CUBE 6
#define INDEX_PlAYER 24
#define ZERO 0
#define ONE 1
#define TWO 2
#define ABS(x) (x) * (((2 * (x)) + 1) % 2)
#define BOOLEAN unsigned short
//---------------------------------------------------------------------------------------
// NumBBiggerThenNumA
// ------------------
//
// General : Checks if the second number (B) is greater than the first number (A).
//
// Parameters :
// number1 - first number (int)
// number2 - second number (int)
//
// Return value : If the second number (B) is greater than the first number (A) (BOOLEAN).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 21.10.2019
//---------------------------------------------------------------------------------------
BOOLEAN NumBBiggerThenNumA(int a, int b)
{
int sub = a - b + ONE;
BOOLEAN answer = (ONE / (ABS(sub) + (sub) + ONE));
return answer;
}
//---------------------------------------------------------------------------------------
// ChangeBool
// ----------
//
// General : Boolean variable inverse.
//
// Parameters :
// bool1 - Boolean variable (BOOLEAN)
//
// Return value : Boolean variable (BOOLEAN).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 21.10.2019
//---------------------------------------------------------------------------------------
BOOLEAN ChangeBool(BOOLEAN bool1)
{
BOOLEAN answer = ++bool1 % TWO;
return answer;
}
//---------------------------------------------------------------------------------------
// Exercise 2
// ----------
//
// General : The program checks the amount of cube flips for which the player
// can advance his tool forward.
//
// Input : None.
//
// Process : The program counts the number of zeros on the board to position 6
// after the player's position on the board.
//
// Output : The amount of cube throws for which the player can advance
// his tool (unsigned short).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : 211675038
// Date : 23.10.2019
//---------------------------------------------------------------------------------------
void main(void)
{
unsigned short board[N] =
{0,1,0,1,0,1,0,0,1,1,1,0,0,0,1,1,0,1,0,1,0,0,0,0,0,1,1,1,1,0};
unsigned short sum = ZERO,
counter = INDEX_PlAYER,
last_step = counter + CUBE;
for (++counter; NumBBiggerThenNumA(counter, last_step); counter++)
{
sum += ChangeBool(board[counter]);
}
printf("Sum: %hu\n", sum);
}

BIN
6/ex3 Normal file

Binary file not shown.

65
6/ex3.c Normal file
View File

@@ -0,0 +1,65 @@
#include <stdio.h>
#define N 20
#define ZERO 0
#define ONE 1
#define ABS(x) (x) * (((2 * (x)) + 1) % 2)
#define BOOLEAN unsigned short
//---------------------------------------------------------------------------------------
// Equality
// --------
//
// General : Checks whether two numbers are equal in value.
//
// Parameters :
// number1 - first number (int)
// number2 - second number (int)
//
// Return value : If there is an equality between the two numbers (BOOLEAN).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 21.10.2019
//---------------------------------------------------------------------------------------
BOOLEAN Equality(int number1, int number2)
{
int sub = number1 - number2;
BOOLEAN answer = (ONE / (ABS(sub) + ONE));
return answer;
}
//---------------------------------------------------------------------------------------
// Exercise 3
// ----------
//
// General : The program checks the number of neighboring organs whose values are equal.
//
// Input : None.
//
// Process : The program checks the number of neighboring organs whose values are equal.
//
// Output : The number of neighboring organ pairs whose values
// are equal (unsigned short).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : 211675038
// Date : 23.10.2019
//---------------------------------------------------------------------------------------
void main(void)
{
unsigned short board[N] =
{1,1,3,3,4,5,5,6,7,7,4,3,2,3,1,1,0,1,0,1};
unsigned short sum = ZERO;
unsigned short counter;
for (counter = ONE; counter < N; counter++)
{
sum += Equality(board[counter - ONE], board[counter]);
}
printf("Sum: %hu\n", sum);
}

BIN
6/ex4 Normal file

Binary file not shown.

75
6/ex4.c Normal file
View File

@@ -0,0 +1,75 @@
#include <stdio.h>
#define N 20
#define ZERO 0
#define ONE 1
#define TWO 2
#define ABS(x) (x) * (((2 * (x)) + 1) % 2)
#define BOOLEAN unsigned short
//---------------------------------------------------------------------------------------
// Equality
// --------
//
// General : Checks whether two numbers are equal in value.
//
// Parameters :
// number1 - first number (int)
// number2 - second number (int)
//
// Return value : If there is an equality between the two numbers (BOOLEAN).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 21.10.2019
//---------------------------------------------------------------------------------------
BOOLEAN Equality(int number1, int number2)
{
int sub = number1 - number2;
BOOLEAN answer = (ONE / (ABS(sub) + ONE));
return answer;
}
//---------------------------------------------------------------------------------------
// Exercise 4
// ----------
//
// General : The program checks several pairs of consecutive characters that are
// equal to the last pair of characters in the array.
//
// Input : 20 chars.
//
// Process : The program checks several pairs of consecutive characters that are
// equal to the last pair of characters in the array.
//
// Output : The number of consecutive character pairs that equals the last
// pair of characters in the array (unsigned short).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : 211675038
// Date : 23.10.2019
//---------------------------------------------------------------------------------------
void main(void)
{
char array[N];
unsigned short loop_counter,
count = ZERO,
new_size_array = N - TWO;
printf("Enter char 20 chars: \n");
for (loop_counter = ZERO; loop_counter < N; loop_counter++)
{
scanf("%c", &array[loop_counter]);
}
for (loop_counter = ONE; loop_counter < new_size_array; loop_counter++)
{
count += Equality((int)array[loop_counter - ONE], (int)array[N - TWO]) *
Equality((int)array[loop_counter], (int)array[N - ONE]);
}
printf("Count: %hd\n", count);
}

BIN
6/ex5 Normal file

Binary file not shown.

80
6/ex5.c Normal file
View File

@@ -0,0 +1,80 @@
#include <stdio.h>
#define N 25
#define ONE 1
#define BOOLEAN unsigned short
#define ABS(x) (x) * (((2 * (x)) + 1) % 2)
#define ZERO 0
//---------------------------------------------------------------------------------------
// NumBBiggerThenNumA
// ------------------
//
// General : Checks if the second number (B) is greater than the first number (A).
//
// Parameters :
// number1 - first number (int)
// number2 - second number (int)
//
// Return value : If the second number (B) is greater than the first number (A) (BOOLEAN).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : None
// Date : 21.10.2019
//---------------------------------------------------------------------------------------
BOOLEAN NumBBiggerThenNumA(int a, int b)
{
int sub = a - b + ONE;
BOOLEAN answer = (ONE / (ABS(sub) + (sub) + ONE));
return answer;
}
//---------------------------------------------------------------------------------------
// Exercise 5
// ----------
//
// General : The program checks if the tool can move in other rule.
//
// Input : 25 numbers, index of player(number), cube result(number).
//
// Process : The program checks the place and the dice roll
// and then it checks if it has to go back or can go forward.
//
// Output : The new place of the tool on the board according to the
// cube roll (unsigned short).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : 211675038
// Date : 23.10.2019
//---------------------------------------------------------------------------------------
void main(void)
{
unsigned short board[N] = { ZERO },
start_index_player,
cube_result,
end_player_index,
counter,
input;
for (counter = ZERO; counter < N; counter++)
{
printf("Enter number for index %ud on borad : ", counter);
scanf("%ud", &input);
}
printf("Enter index of player: ");
scanf("%ud", &start_index_player);
printf("Enter cube result: ");
scanf("%ud", &cube_result);
end_player_index = start_index_player + ONE;
end_player_index -= NumBBiggerThenNumA(board[end_player_index],
cube_result) * (cube_result + ONE);
printf("%hd\n", end_player_index);
}

BIN
6/ex6 Normal file

Binary file not shown.

49
6/ex6.c Normal file
View File

@@ -0,0 +1,49 @@
#include <stdio.h>
#define COUNT_CHANNELS 10
#define ZERO 0
#define ONE 1
#define TWO 2
//---------------------------------------------------------------------------------------
// Exercise 6
// ----------
//
// General : The program counts several channels above the average viewing percentage.
//
// Input : 40 numbers (0 - 100) (unsigned short).
//
// Process : The program calculates the average viewing percentage, and counts how
// many channels are in the field above average.
//
// Output : Number of channels above average viewership percentage.
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : 211675038
// Date : 23.10.2019
//---------------------------------------------------------------------------------------
void main(void)
{
unsigned short channels[COUNT_CHANNELS] = { ZERO },
counter,
percent,
sum = ZERO,
avg,
counter = ZERO;
for (counter = ZERO; counter < COUNT_CHANNELS; counter++)
{
printf("Enter percet of viewers: ");
scanf("%hd", &percent);
channels[counter] = percent;
}
for (counter = ZERO; counter < COUNT_CHANNELS; counter++)
sum += channels[counter];
// According to the second section "avg" should be changed to 20
avg = sum / COUNT_CHANNELS;
for (counter = ZERO; channels[counter] > avg; counter++);
printf("Above avg: %hd\n", counter);
}