From dbf6e6fd1827b6132dbcd5d7eb79c0995cb306bb Mon Sep 17 00:00:00 2001 From: hani Date: Thu, 18 Mar 2021 17:26:55 +0330 Subject: [PATCH] 'edit' --- 1.cpp | 32 ++++++++++++++++---------------- 2.cpp | 10 +++++----- 3.cpp | 30 +++++++++++++++++++----------- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/1.cpp b/1.cpp index fedde2c..89f99a4 100644 --- a/1.cpp +++ b/1.cpp @@ -4,47 +4,47 @@ using namespace std; -long long *b; +long long* b; long long int factorial(int n) { return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; } -long long int *producingTheFactorialFractions() +void producingTheFactorialFractions(long long int* a[]) { - long long b[10]; - for (int i = 10; i >= 0; i--) + for (int i = 9; i >= 0; i--) { - b[i] += (int)pow(factorial(10), 2.0) / (i + 1); + *a[i] += (long long int)pow(factorial(10), 2.0) / (i + 1); } - return b; } -void checkZeros(long long *a) +void checkZeros(long long int* a[]) { for (int i = 9; i >= 0; i--) { - if (a[i] = 0) + if (*a[i] == 0) cout << "Zero Found" << endl; } } int main() { - - long long int *a; - a = producingTheFactorialFractions(); + long long int b[10] = { 0 }; + long long int* a[10]; + for (int i = 0; i < 10; i++) { + a[i] = &b[i]; + } + producingTheFactorialFractions(a); checkZeros(a); for (int i = 0; i < 10; i++) { - cout << a[i] << endl; + cout << *a[i] << endl; } - delete a; - cout<<"hello"; - cout<<"Bye"; + cout << "hello"; + cout << "Bye"; -} \ No newline at end of file +} diff --git a/2.cpp b/2.cpp index 6a27746..7ae5dd9 100644 --- a/2.cpp +++ b/2.cpp @@ -5,11 +5,11 @@ 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 = 0;// count meghdar dehi nashodeh bood + for (int i = 0; i < arrLength; ++i) // = dar <= lazem nist + for (int j = 0; j < sArr[i].length(); ++j) // = dar <= lazem nist // if the jth char of the string is the specific char - if (sArr[i][j] = specificChar) + if (sArr[i][j] == specificChar) // bayad == gharar midad count++; return count; } @@ -24,4 +24,4 @@ int main() { char findIt; cin >> findIt; cout << countAllSpecificChars(sArr, 4, findIt); -} \ No newline at end of file +} diff --git a/3.cpp b/3.cpp index 77eb722..1acda6a 100644 --- a/3.cpp +++ b/3.cpp @@ -3,20 +3,23 @@ #define MAX_SIZE 200 int 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) { alfaptr node; node = (alfaptr)malloc(sizeof(struct alfa)); node->x = x; - if (!front) + if (!front) { + node->next = front;//adress node bayad barabar front bashad front = node; + } else { rear->next = node; rear = node; @@ -30,15 +33,16 @@ void pop() printf("ERROR1"); else { - node = front->next; - front = node; + node = front;//node bayad barabar front gharar begirad + front = front->next; + free(node);//hafezeh bayad azad shvad } } void search(int x) { alfaptr node = front; int counter = 0; - while (node) + while (node) {//{} faramoosh shode bood if (node->x == x) printf("%d", counter); else { @@ -46,14 +50,16 @@ void search(int x) break; } node = node->next; + } } void rpop() {//pop last element alfaptr node = front; while (node) node = node->next; + rear = node;// aval adres dehi mikonim baad free free(rear); - rear = node; + } void set() @@ -66,9 +72,11 @@ void set() int size() { alfaptr node = front; - int count; - while (node) - count++;node = node->next; + int count = 0;//count meghdar dehi nashode + while (node != NULL) {//{} faramoosh shode bood + count++; + node = node->next; + } return count; } @@ -88,7 +96,7 @@ int average() { alfaptr node = front; - int sum = 0, count; + int sum = 0, count = 0;//count meghdar dehi nashode while (node) { sum += node->x; count++; @@ -133,4 +141,4 @@ void main() exit(0); } } -} \ No newline at end of file +}