diff --git a/1.cpp b/1.cpp index fedde2c..fe2f3e3 100644 --- a/1.cpp +++ b/1.cpp @@ -1,32 +1,35 @@ #include #include #include - +#include using namespace std; -long long *b; +//long long int* m; +void test_factorial(); long long int factorial(int n) { return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; } -long long int *producingTheFactorialFractions() +long long int* producingTheFactorialFractions() { - long long b[10]; - - for (int i = 10; i >= 0; i--) - { - b[i] += (int)pow(factorial(10), 2.0) / (i + 1); + long long int b[10] = { 0 }; + //int i = 10 + long long int m; + for (int i = 9; i >= 0; i--) + { //(int) + m = (long long int)pow(factorial(10), 2.0); + b[i] += (long long int)pow(factorial(10), 2.0) / (i + 1); } return b; } -void checkZeros(long long *a) +void checkZeros(long long int a[10]) { for (int i = 9; i >= 0; i--) - { - if (a[i] = 0) + { //a[i] = 0 + if (a[0] == 0) cout << "Zero Found" << endl; } } @@ -34,17 +37,26 @@ void checkZeros(long long *a) int main() { - long long int *a; + long long int* a; + // + a = new long long int[10]; a = producingTheFactorialFractions(); - checkZeros(a); + + long long int a2[10]; for (int i = 0; i < 10; i++) - { - cout << a[i] << endl; - } - delete a; + a2[i] = a[i]; - cout<<"hello"; - cout<<"Bye"; + checkZeros(a2); + for (int i = 0; i < 10; i++) + { + cout << a2[i] << endl; + } + //delete[] a; +} -} \ No newline at end of file +void test_factorial() +{ + long long int a = factorial(10); + assert(a == 3628800); +} diff --git a/2.cpp b/2.cpp index 6a27746..5dabfdd 100644 --- a/2.cpp +++ b/2.cpp @@ -5,11 +5,15 @@ using namespace std; // count all the specific char in the whole array of strings int countAllSpecificChars(string sArr[], int arrLength, char specificChar) { - int count; - for (int i = 0; i <= arrLength; ++i) - for (int j = 0; j <= sArr[i].size(); ++j) + //int count; + int count = 0; + //i <= arrLength + for (int i = 0; i < arrLength; ++i) + // j <= sArr[i].size() + for (int j = 0; j < sArr[i].size(); ++j) // if the jth char of the string is the specific char - if (sArr[i][j] = specificChar) + //sArr[i][j] = specificChar + if (sArr[i][j] == specificChar) count++; return count; } diff --git a/3.cpp b/3.cpp index 77eb722..a36d6ed 100644 --- a/3.cpp +++ b/3.cpp @@ -1,22 +1,33 @@ #include #include +#pragma warning(disable:4996) #define MAX_SIZE 200 -int arr[MAX_SIZE]; +//int arr[MAX_SIZE]; +long long arr[MAX_SIZE]; -typedef struct alfa * alfaptr; + +typedef struct alfa* alfaptr; struct alfa { long long x; alfaptr next; }; alfaptr rear = NULL, front = NULL; -void push(int x) + +//int x +void push(long long x) { alfaptr node; node = (alfaptr)malloc(sizeof(struct alfa)); node->x = x; + // + node->next = NULL; if (!front) + { front = node; + // + rear = node; + } else { rear->next = node; rear = node; @@ -25,33 +36,57 @@ void push(int x) void pop() { - alfaptr node; if (!front) printf("ERROR1"); else { - node = front->next; - front = node; + // + alfaptr node = front; + //node = front->next; + //front = node; + // + front = node->next; + free(node); } } -void search(int x) + +//int +void search(long long x) { alfaptr node = front; int counter = 0; while (node) + //{} + { if (node->x == x) + { + // + counter++; printf("%d", counter); + } else { printf("ERROR2"); - break; + //break; } node = node->next; + } } void rpop() {//pop last element + + // + if (front == rear) + { + front = NULL; + rear = NULL; + return; + } alfaptr node = front; - while (node) + //node + while (node->next != rear) node = node->next; + // + node->next = NULL; free(rear); rear = node; } @@ -66,9 +101,13 @@ void set() int size() { alfaptr node = front; - int count; + //count + int count = 0; while (node) - count++;node = node->next; + { + count++; + node = node->next; + } return count; } @@ -76,7 +115,7 @@ void show() { if (!front) { for (int i = 0; i < MAX_SIZE; i++) - printf("%d ", arr[i]); + printf("%lld ", arr[i]); } else { @@ -84,11 +123,13 @@ void show() } } -int average() +//long long +long long average() { alfaptr node = front; - int sum = 0, count; + //int //count + long long sum = 0, count = 0; while (node) { sum += node->x; count++;