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

1190
8/IdanLib.h Normal file

File diff suppressed because it is too large Load Diff

181
8/IdanLibPointers.h Normal file
View File

@@ -0,0 +1,181 @@
#include "IdanLib.h"
#define N 3
unsigned short CountCharInColumn(char mat[][N], unsigned short row_size ,unsigned short column, char c)
{
unsigned short count = ZERO,
counter;
for (counter = ZERO; counter < row_size; counter++)
{
count += (mat[counter][column] == c);
}
return (count);
}
unsigned short CountCharInRow(char mat[][N], unsigned short col_size ,unsigned short row, char c)
{
unsigned short count = ZERO,
counter;
for (counter = ZERO; counter < col_size; counter++)
{
count += (mat[row][counter] == c);
}
return (count);
}
unsigned short CountCharInMainDiagonal(char mat[][N], unsigned short size, char c)
{
unsigned short count = ZERO,
counter;
for (counter = ZERO; counter < size; counter++)
{
count += (mat[size][size] == c);
}
return (count);
}
unsigned short CountCharInSecondaryDiagonal(char mat[][N], unsigned short size, char c)
{
unsigned short count = ZERO,
counter;
for (counter = ZERO; counter < size; counter++)
{
count += (mat[size][N - size] == c);
}
return (count);
}
void OutputPrintMatrix(char mat[][N], unsigned int row_size, unsigned int column_size)
{
unsigned int counter_row,
counter_col;
for (counter_row = ZERO; counter_row < row_size; counter_row++)
{
for (counter_col = ZERO; counter_col < column_size; counter_col++)
{
printf("%c, ", mat[counter_row][counter_col]);
}
printf("\n");
}
}
unsigned short MaxNumberInArray(unsigned short array[], int size)
{
int max = array[ZERO],
counter = ONE;
for (counter = ONE; counter < size; counter++)
{
max = (array[counter] > max) ? array[counter] : max;
}
return (max);
}
unsigned short MaxCountNumberInColumn(int mat[][N], unsigned short row_size ,unsigned short column)
{
unsigned short counter_array[TEN] = { ZERO },
counter,
max;
for (counter = ZERO; counter < row_size; counter++)
{
counter_array[mat[counter][column]]++;
}
max = MaxNumberInArray(counter_array, TEN);
return (max);
}
unsigned short MaxCountNumberInRow(int mat[][N], unsigned short col_size ,unsigned short row)
{
unsigned short counter_array[TEN] = { ZERO },
counter,
max;
for (counter = ZERO; counter < col_size; counter++)
{
counter_array[mat[row][counter]]++;
}
max = MaxNumberInArray(counter_array, TEN);
return (max);
}
BOOLEAN IsLatinSquare(int mat[][N], unsigned short row_size)
{
unsigned short counter = ZERO;
BOOLEAN is_latin_square = TRUE;
while ((row_size - counter) * is_latin_square)
{
is_latin_square *= (MaxCountNumberInColumn(mat, row_size, counter) == ONE) *
(MaxCountNumberInRow(mat, row_size, counter) == ONE);
counter++;
}
return (is_latin_square);
}
void InputMatrix(int mat[][N], unsigned short row_size)
{
unsigned short counter,
area = row_size * row_size;
for (counter = ZERO; counter < area; counter++)
{
scanf(" %d", &mat[counter / row_size][counter % row_size]);
}
}
int ColumnSum(int mat[][N], unsigned short row_size ,unsigned short column)
{
unsigned short counter;
int sum = ZERO;
for (counter = ZERO; counter < row_size; counter++)
{
sum += mat[counter][column];
}
return (sum);
}
int RowSum(int mat[][N], unsigned short col_size ,unsigned short row)
{
unsigned short counter;
int sum = ZERO;
for (counter = ZERO; counter < col_size; counter++)
{
sum += mat[row][counter];
}
return (sum);
}
int MainDiagonalSum(char mat[][N], unsigned short col_size)
{
unsigned short counter;
int sum = ZERO;
for (counter = ZERO; counter < col_size; counter++)
{
sum += mat[counter][counter];
}
return (sum);
}
int SecondaryDiagonalSum(int mat[][N], unsigned short col_size)
{
unsigned short counter;
int sum = ZERO;
for (counter = ZERO; counter < col_size; counter++)
{
sum += mat[counter][col_size - ONE - counter];
}
return (sum);
}

BIN
8/ex1 Normal file

Binary file not shown.

134
8/ex1.c Normal file
View File

@@ -0,0 +1,134 @@
#include "IdanLib.h"
#include <stdio.h>
#define N 3
unsigned short CountCharInColumn(char mat[][N], unsigned short row_size ,unsigned short column, char c)
{
unsigned short count = ZERO,
counter;
for (counter = ZERO; counter < row_size; counter++)
{
count += (mat[counter][column] == c);
}
return (count);
}
unsigned short CountCharInRow(char mat[][N], unsigned short col_size ,unsigned short row, char c)
{
unsigned short count = ZERO,
counter;
for (counter = ZERO; counter < col_size; counter++)
{
count += (mat[row][counter] == c);
}
return (count);
}
unsigned short CountCharInMainDiagonal(char mat[][N], unsigned short size, char c)
{
unsigned short count = ZERO,
counter;
for (counter = ZERO; counter < size; counter++)
{
count += (mat[size][size] == c);
}
return (count);
}
unsigned short CountCharInSecondaryDiagonal(char mat[][N], unsigned short size, char c)
{
unsigned short count = ZERO,
counter;
for (counter = ZERO; counter < size; counter++)
{
count += (mat[size][N - size] == c);
}
return (count);
}
BOOLEAN CheckWin(char mat[][N], unsigned short size, char c)
{
BOOLEAN win = (CountCharInMainDiagonal(mat, size, c) == THREE) +
(CountCharInSecondaryDiagonal(mat, size, c) == THREE);
unsigned short counter = ZERO;
while (!win * (size - counter))
{
win = (CountCharInColumn(mat, size, counter, c) == THREE) +
(CountCharInRow(mat, size, counter, c) == THREE);
counter++;
}
win = (win > ZERO);
return (win);
}
char InputChar()
{
char c;
scanf(" %c", &c);
return (c);
}
unsigned short InputUnsignedShort()
{
unsigned short number;
scanf("%hu", &number);
return (number);
}
void OutputPrintRequestForChar()
{
printf("Enter 'X' or 'O': ");
}
void OutputPrintRequestForColAndRow()
{
printf("Enter column and row: ");
}
void OutputPrintWhoWin(char c)
{
printf("The winner is: %c\n", c);
}
void OutputPrintMatrix(char mat[][N], unsigned int row_size, unsigned int column_size)
{
unsigned int counter_row,
counter_col;
for (counter_row = ZERO; counter_row < row_size; counter_row++)
{
for (counter_col = ZERO; counter_col < column_size; counter_col++)
{
printf("%c, ", mat[counter_row][counter_col]);
}
printf("\n");
}
}
void main(void)
{
char mat[N][N] = { ZERO };
BOOLEAN win = FALSE;
char input;
unsigned short col,
row;
while (!win)
{
OutputPrintRequestForChar();
input = InputChar();
OutputPrintRequestForColAndRow();
col = InputUnsignedShort();
row = InputUnsignedShort();
mat[row][col] = input;
win = CheckWin(mat, N, input);
OutputPrintMatrix(mat, N, N);
}
OutputPrintWhoWin(input);
}

BIN
8/ex2 Normal file

Binary file not shown.

112
8/ex2.c Normal file
View File

@@ -0,0 +1,112 @@
#include "IdanLib.h"
#include <stdio.h>
#define N 3
unsigned short MaxNumberInArray(unsigned short array[], int size)
{
int max = array[ZERO],
counter = ONE;
for (counter = ONE; counter < size; counter++)
{
max = (array[counter] > max) ? array[counter] : max;
}
return (max);
}
unsigned short MaxCountNumberInColumn(int mat[][N], unsigned short row_size ,unsigned short column)
{
unsigned short counter_array[TEN] = { ZERO },
counter,
max;
for (counter = ZERO; counter < row_size; counter++)
{
counter_array[mat[counter][column]]++;
}
max = MaxNumberInArray(counter_array, TEN);
return (max);
}
unsigned short MaxCountNumberInRow(int mat[][N], unsigned short col_size ,unsigned short row)
{
unsigned short counter_array[TEN] = { ZERO },
counter,
max;
for (counter = ZERO; counter < col_size; counter++)
{
counter_array[mat[row][counter]]++;
}
max = MaxNumberInArray(counter_array, TEN);
return (max);
}
BOOLEAN IsLatinSquare(int mat[][N], unsigned short row_size)
{
unsigned short counter = ZERO;
BOOLEAN is_latin_square = TRUE;
while ((row_size - counter) * is_latin_square)
{
is_latin_square *= (MaxCountNumberInColumn(mat, row_size, counter) == ONE) *
(MaxCountNumberInRow(mat, row_size, counter) == ONE);
counter++;
}
return (is_latin_square);
}
unsigned short InputUnsignedShort()
{
unsigned short number;
scanf("%hu", &number);
return (number);
}
void InputMatrix(int mat[][N], unsigned short row_size)
{
unsigned short counter,
area = row_size * row_size;
for (counter = ZERO; counter < area; counter++)
{
scanf(" %d", &mat[counter / row_size][counter % row_size]);
}
}
void OutputPrintRequestForMatrix()
{
printf("Enter 9 numbers for matrix: ");
}
void OutputPrintLatinSquare(BOOLEAN is_latin_square)
{
printf("This is latin square: %hu\n", is_latin_square);
}
void OutputPrintMatrix(int mat[][N], unsigned int row_size, unsigned int column_size)
{
unsigned int counter_row,
counter_col;
for (counter_row = ZERO; counter_row < row_size; counter_row++)
{
for (counter_col = ZERO; counter_col < column_size; counter_col++)
{
printf("%d, ", mat[counter_row][counter_col]);
}
printf("\n");
}
}
void main(void)
{
int mat[N][N] = { ZERO };
OutputPrintRequestForMatrix();
InputMatrix(mat, N);
OutputPrintMatrix(mat, N, N);
OutputPrintLatinSquare(IsLatinSquare(mat, N));
}

BIN
8/ex3 Normal file

Binary file not shown.

120
8/ex3.c Normal file
View File

@@ -0,0 +1,120 @@
#include "IdanLib.h"
#include <stdio.h>
#define N 3
int ColumnSum(int mat[][N], unsigned short row_size ,unsigned short column)
{
unsigned short counter;
int sum = ZERO;
for (counter = ZERO; counter < row_size; counter++)
{
sum += mat[counter][column];
}
return (sum);
}
int RowSum(int mat[][N], unsigned short col_size ,unsigned short row)
{
unsigned short counter;
int sum = ZERO;
for (counter = ZERO; counter < col_size; counter++)
{
sum += mat[row][counter];
}
return (sum);
}
int MainDiagonalSum(char mat[][N], unsigned short col_size)
{
unsigned short counter;
int sum = ZERO;
for (counter = ZERO; counter < col_size; counter++)
{
sum += mat[counter][counter];
}
return (sum);
}
int SecondaryDiagonalSum(int mat[][N], unsigned short col_size)
{
unsigned short counter;
int sum = ZERO;
for (counter = ZERO; counter < col_size; counter++)
{
sum += mat[counter][col_size - ONE - counter];
}
return (sum);
}
int InputInt()
{
int num;
scanf(" %d", &num);
return (num);
}
BOOLEAN IsMagicSqaure(int mat[][N], unsigned short row_size)
{
int sum = MainDiagonalSum(mat, row_size);
BOOLEAN is_magic_sqaure = (sum == SecondaryDiagonalSum(mat, row_size));
unsigned short counter = ZERO;
while ((row_size - counter) * is_magic_sqaure)
{
is_magic_sqaure *= (ColumnSum(mat, row_size, counter) == sum) *
(RowSum(mat, row_size, counter) == sum);
counter++;
}
return (is_magic_sqaure);
}
void InputMatrix(int mat[][N], unsigned short row_size)
{
unsigned short counter,
area = row_size * row_size;
for (counter = ZERO; counter < area; counter++)
{
mat[counter / row_size][counter % row_size] = InputInt();
}
}
void OutputPrintRequestForMatrix()
{
printf("Enter 9 numbers for matrix: ");
}
void OutputPrintMagicSquare(BOOLEAN is_magic_square)
{
printf("This is magic square: %hu\n", is_magic_square);
}
void OutputPrintMatrix(int mat[][N], unsigned int row_size, unsigned int column_size)
{
unsigned int counter_row,
counter_col;
for (counter_row = ZERO; counter_row < row_size; counter_row++)
{
for (counter_col = ZERO; counter_col < column_size; counter_col++)
{
printf("%d, ", mat[counter_row][counter_col]);
}
printf("\n");
}
}
void main(void)
{
int mat[N][N] = { ZERO };
OutputPrintRequestForMatrix();
InputMatrix(mat, N);
OutputPrintMatrix(mat, N, N);
OutputPrintMagicSquare(IsMagicSqaure(mat, N));
}

93
8/ex4.c Normal file
View File

@@ -0,0 +1,93 @@
#include "IdanLib.h"
#include <stdio.h>
#define M 8
#define N 10
int ColumnSum(int mat[][N], unsigned short row_size ,unsigned short column)
{
unsigned short counter;
int sum = ZERO;
for (counter = ZERO; counter < row_size; counter++)
{
sum += mat[counter][column];
}
return (sum);
}
int RowSum(int mat[][N], unsigned short col_size ,unsigned short row)
{
unsigned short counter;
int sum = ZERO;
for (counter = ZERO; counter < col_size; counter++)
{
sum += mat[row][counter];
}
return (sum);
}
unsigned short SumArray(unsigned short array[], unsigned short start, unsigned short end)
{
int sum = ZERO,
counter;
for (counter = start; counter < end; counter++)
{
sum += array[counter];
}
return (sum);
}
unsigned short IndexOfRangeMaxSum(int vector, unsigned short vector_size, unsigned short count_index)
{
int index_max_sum,
max_sum = ZERO,
sum;
unsigned short new_size = vector - count_index;
unsigned short counter;
for (counter = ZERO; counter < new_size; counter++)
{
sum = SumArray(vector, counter, counter + count_index);
if (sum > max_sum)
{
sum = max_sum;
index_max_sum = counter;
}
}
return (index_max_sum);
}
void SumOfNumberInRows(int mat[M][N], int sum_row[M], int number)
{
unsigned short counter;
unsigned int area = N * M;
for ( counter = ZERO; counter < area; counter++)
{
sum_row[counter / N] += (mat[counter / N][counter % N] == number);
}
}
void SumOfNumberInColumns(int mat[M][N], int sum_col[N], int number)
{
unsigned short counter;
unsigned int area = N * M;
for ( counter = ZERO; counter < area; counter++)
{
sum_col[counter % N] += (mat[counter / N][counter % N] == number);
}
}
void main(void)
{
unsigned int L;
int mat[M][N] = { ZERO };
int sum_row[M] = { ZERO };
int sum_col[N] = { ZERO };
}

BIN
8/test Normal file

Binary file not shown.

50
8/test.c Normal file
View File

@@ -0,0 +1,50 @@
#include "IdanLib.h"
#include <stdio.h>
#define N 7
#define N2 6
#define REMOVE_COL 3
#define REMOVE_ROW 5
void OutputPrintMatrix(int mat[][N2], unsigned int row_size, unsigned int column_size)
{
unsigned int counter_row,
counter_col;
for (counter_row = ZERO; counter_row < row_size; counter_row++)
{
for (counter_col = ZERO; counter_col < column_size; counter_col++)
{
printf("%d ", mat[counter_row][counter_col]);
}
printf("\n");
}
}
void main(void)
{
int mat1[N][N] = { ZERO };
int mat2[N2][N2] = { ZERO };
int row1, col1, row2, col2;
for (unsigned short i = 0; i < N * N; i++)
{
mat1[i / N][i % N] = i+1;
}
for (unsigned counter = (REMOVE_ROW * (N2) + REMOVE_COL); counter < (N2 * N2) + (REMOVE_ROW * (N2) + REMOVE_COL) ; counter++)
{
row2 = ((counter - REMOVE_COL)/ N2) % N2;
col2 = (counter % N2);
row1 = (((counter - REMOVE_COL) / N2) + ((N - N2) * ((counter / N2) >= REMOVE_ROW))) % N;
col1 = ((counter % N2) + ((N - N2) * ((counter % N2) >= REMOVE_COL))) % N;
mat2[row2][col2] = mat1[row1][col1];
}
printf("\n\n");
OutputPrintMatrix(mat2, N2, N2);
}