First Upload
This commit is contained in:
45
4/ex1.c
Normal file
45
4/ex1.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define BOOLEAN unsigned short
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define TEN 10
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exercise 1
|
||||
// ----------
|
||||
//
|
||||
// General : The program checks if there is at least one common digit between 2 numbers.
|
||||
//
|
||||
// Input : 2 numbers.
|
||||
//
|
||||
// Process : The program checks check every digit of 2 numbers.
|
||||
//
|
||||
// Output : 0(FALSE), 1(TRUE).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 23.09.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
short num1,
|
||||
num2,
|
||||
temp_num1,
|
||||
temp_num2,
|
||||
digit_num1,
|
||||
digit_num2;
|
||||
BOOLEAN answer = FALSE;
|
||||
|
||||
printf("Enter 2 numbers: ");
|
||||
scanf("%hd%hd", &num1, &num2);
|
||||
|
||||
for (temp_num1 = num1, temp_num2 = num2; temp_num1 && !answer;
|
||||
(!temp_num2) ?
|
||||
temp_num2 = num2, temp_num1 /= TEN:
|
||||
(temp_num1 % TEN == temp_num2 % TEN) ?
|
||||
answer = TRUE :
|
||||
(temp_num2 /= TEN));
|
||||
|
||||
printf("The answer is: %hu\n", answer);
|
||||
}
|
||||
45
4/ex1.c.save
Normal file
45
4/ex1.c.save
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define BOOLEAN unsigned short
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define TEN 10
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exercise 1
|
||||
// ----------
|
||||
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm//
|
||||
// General : The program checks if there is at least one common digit between 2 numbers.
|
||||
//
|
||||
// Input : 2 numbers.
|
||||
//
|
||||
// Process : The program checks check every digit of 2 numbers.
|
||||
//
|
||||
// Output : 0(FALSE), 1(TRUE).
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 23.09.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
short num1,
|
||||
num2,
|
||||
temp_num1,
|
||||
temp_num2,
|
||||
digit_num1,
|
||||
digit_num2;
|
||||
BOOLEAN answer = FALSE;
|
||||
|
||||
printf("Enter 2 numbers: ");
|
||||
scanf("%hd%hd", &num1, &num2);
|
||||
|
||||
for (temp_num1 = num1, temp_num2 = num2; temp_num1 && !answer;
|
||||
(!temp_num2) ?
|
||||
temp_num2 = num2, temp_num1 /= TEN:
|
||||
(temp_num1 % TEN == temp_num2 % TEN) ?
|
||||
answer = TRUE :
|
||||
(temp_num2 /= TEN));
|
||||
|
||||
printf("The answer is: %hu\n", answer);
|
||||
}
|
||||
17
4/ex2.c
Normal file
17
4/ex2.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define EOD -1
|
||||
|
||||
void main(void)
|
||||
{
|
||||
short num = 0,
|
||||
count = 0,
|
||||
sum = 0;
|
||||
|
||||
for (count = 0; num != EOD; count++)
|
||||
{
|
||||
printf("Enter number (-1 to stop): ");
|
||||
scanf("%hd", &num);
|
||||
sum += num;
|
||||
}
|
||||
}
|
||||
32
4/ex3.c
Normal file
32
4/ex3.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define THREE 3
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exercise 3
|
||||
// ----------
|
||||
//
|
||||
// General : The program prints the smallest power of 3 larger than the input.
|
||||
//
|
||||
// Input : Number.
|
||||
//
|
||||
// Process : The program check all power of 3 until that is smaller than input.
|
||||
//
|
||||
// Output : Number.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 23.09.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
unsigned short num;
|
||||
unsigned int result;
|
||||
|
||||
printf("Enter number: ");
|
||||
scanf("%hd", &num);
|
||||
for (result = THREE; num > result; result *= THREE);
|
||||
|
||||
printf("%d\n", result);
|
||||
|
||||
}
|
||||
44
4/ex4.c
Normal file
44
4/ex4.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX(a,b) (a > b) ? a : b
|
||||
#define MIN(a,b) (a < b) ? a : b
|
||||
#define ONE 1
|
||||
#define ZERO 0
|
||||
#define TEN 10
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exercise 4
|
||||
// ----------
|
||||
//
|
||||
// General : The program receives 10 numbers and prints the largest
|
||||
// number and the second largest number.
|
||||
//
|
||||
// Input : 10 numbers.
|
||||
//
|
||||
// Process : The program loop for input and check max and second max .
|
||||
//
|
||||
// Output : 2 number.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 23.09.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
unsigned int num,
|
||||
counter,
|
||||
temp,
|
||||
max_max = ZERO,
|
||||
min_max = ZERO;
|
||||
|
||||
|
||||
for (counter = ZERO; counter < TEN; counter++)
|
||||
{
|
||||
printf("Enter number: ");
|
||||
scanf("%d", &num);
|
||||
(num > max_max) ? (min_max = max_max, max_max = num) : (min_max = MAX(min_max, num));
|
||||
}
|
||||
|
||||
printf("Max_Max: %d\nMin_Max: %d\n", max_max, min_max);
|
||||
|
||||
}
|
||||
46
4/ex5.c
Normal file
46
4/ex5.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX(a, b) (a > b) ? a : b
|
||||
#define MIN(a, b) (a < b) ? a : b
|
||||
#define ZERO 0
|
||||
#define TEN 10
|
||||
#define MAXIMUM_SHORT 32767
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exercise 5
|
||||
// ----------
|
||||
//
|
||||
// General : The program prints the largest, smallest organ, and the sum of the series.
|
||||
// On all series..
|
||||
//
|
||||
// Input : None
|
||||
//
|
||||
// Process : The program do sum of series and take the max mnuber and min number.
|
||||
//
|
||||
// Output : Max, Min, Sum, for evert series.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 23.09.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
long long series = 386946543216; // example for series (start from right)
|
||||
short value,
|
||||
sum = ZERO,
|
||||
amount_values,
|
||||
amount_series;
|
||||
|
||||
unsigned short max = ZERO;
|
||||
short min = MAXIMUM_SHORT;
|
||||
|
||||
for (amount_values = series % TEN, series /= TEN; amount_values;
|
||||
series /= TEN, amount_values--, (!amount_values) ?
|
||||
(printf("MAX: %hd\nMIN: %hd\nSUM: %hd\n", max, min, sum), amount_values = series % TEN, sum = ZERO, max = ZERO, min = MAXIMUM_SHORT, series /= TEN) : ZERO)
|
||||
{
|
||||
value = series % TEN;
|
||||
max = MAX(value, (signed short)max);
|
||||
min = MIN(value, (signed short)min);
|
||||
sum += value;
|
||||
}
|
||||
}
|
||||
39
4/ex6.c
Normal file
39
4/ex6.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define MIN(a,b) (a < b) ? a : b
|
||||
#define THOUSAND 1000
|
||||
#define TWO 2
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exercise 6
|
||||
// ----------
|
||||
//
|
||||
// General : The program prints positive integers that divide the two input
|
||||
// numbers in the field up to 1000.
|
||||
//
|
||||
// Input : Two numbers that don't divide each other.
|
||||
//
|
||||
// Process : The program do a loop.
|
||||
//
|
||||
// Output : Positive integers.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 23.09.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
unsigned short num1,
|
||||
num2,
|
||||
counter;
|
||||
|
||||
printf("Enter 2 numbers: ");
|
||||
scanf("%hu%hu", &num1, &num2);
|
||||
|
||||
for (counter = ((MIN(num2, MIN(num1, THOUSAND))) / TWO); counter; counter--)
|
||||
{
|
||||
if (!((num1 % counter) + (num2 % counter)))
|
||||
printf("%hu\n", counter);
|
||||
}
|
||||
|
||||
}
|
||||
41
4/ex7.c
Normal file
41
4/ex7.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define ZERO 0
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Exercise 7
|
||||
// ----------
|
||||
//
|
||||
// General : The program prints the minimum number of tiles required to
|
||||
// line the length of the line.
|
||||
//
|
||||
// Input : A(number), B(number), N(number).
|
||||
//
|
||||
// Process : The program דubtracts A by N until the remainder of B by N is 0.
|
||||
//
|
||||
// Output : Count of A and count of B.
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
// Programmer : Cohen Idan
|
||||
// Student No : None
|
||||
// Date : 23.09.2019
|
||||
//---------------------------------------------------------------------------------------
|
||||
void main(void)
|
||||
{
|
||||
unsigned short a,
|
||||
b,
|
||||
n,
|
||||
counter,
|
||||
count_a = ZERO,
|
||||
count_b = ZERO;
|
||||
|
||||
printf("Enter A: ");
|
||||
scanf("%hu", &a);
|
||||
printf("Enter B: ");
|
||||
scanf("%hu", &b);
|
||||
printf("Enter N: ");
|
||||
scanf("%hu", &n);
|
||||
|
||||
for (counter = n; counter; (!(counter % b)) ? (count_b = counter / b, counter %= b) : (count_a++, counter -= a));
|
||||
|
||||
printf("Count A: %hu\nCount B: %hu\n", count_a, count_b);
|
||||
}
|
||||
Reference in New Issue
Block a user