diff --git a/1.cpp b/1.cpp index fedde2c..a9e33d1 100644 --- a/1.cpp +++ b/1.cpp @@ -1,50 +1,92 @@ #include #include #include - using namespace std; - -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(unsigned long long int *a) { - long long b[10]; - - for (int i = 10; i >= 0; i--) - { - b[i] += (int)pow(factorial(10), 2.0) / (i + 1); - } - return b; + for (int i = 9; i >= 0; i--) + a[i] =(unsigned long long int)pow(factorial(10), 2.0) / (i + 1); } - -void checkZeros(long long *a) +void checkZeros(unsigned 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(); + unsigned long long int *a; + producingTheFactorialFractions(a); checkZeros(a); for (int i = 0; i < 10; i++) - { cout << a[i] << endl; - } delete a; - cout<<"hello"; - cout<<"Bye"; +} + +////////////bala codee eslah shodas.paiini code avale ke assertion roosh gozashtam. + +//#include +//// uncomment to disable assert() +//// #define NDEBUG +//#include +//// Use (void) to silent unused warnings. +//#define assertm(exp, msg) assert(((void)msg, exp)) +//#include +//#include +// +//using namespace std; +// +//long long *b; +//long long c[10]; +//long long int factorial(int n) +//{ +// return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; +//} +// +//long long int *producingTheFactorialFractions() +//{ +// long long b[10]; +// for (int i = 10; i >= 0; i--) +// { +// assertm(b[i]!=0,"not initialized"); +// b[i] += (int)pow(factorial(10), 2.0) / (i + 1); +// assertm(b[i]<0,"Overflow Error"); +// c[i] += (int)pow(factorial(10), 2.0) / (i + 1); +// } +// return b; +//} +// +//void checkZeros(long long *a) +//{ +// for (int i = 9; i >= 0; i--) +// { +// assertm(a[i]==0,"Zero value"); +// if (a[i] = 0) +// cout << "Zero Found" << endl; +// } +//} +// +//int main() +//{ +// +// long long int *a; +// a = producingTheFactorialFractions(); +// checkZeros(a); +// for (int i = 0; i < 10; i++) +// { +// assertm(c[i]==a[i],"ERROR! garbage value found."); +// cout << a[i] << endl; +// } +// delete a; +// +//} + + -} \ No newline at end of file diff --git a/2.cpp b/2.cpp index 6a27746..6d7765d 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; + for (int i = 0; i < arrLength; ++i) + 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) + if (sArr[i][j] == specificChar) 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..bdefe46 100644 --- a/3.cpp +++ b/3.cpp @@ -6,7 +6,7 @@ int arr[MAX_SIZE]; typedef struct alfa * alfaptr; struct alfa { - long long x; + int x; alfaptr next; }; alfaptr rear = NULL, front = NULL; @@ -15,8 +15,10 @@ void push(int x) alfaptr node; node = (alfaptr)malloc(sizeof(struct alfa)); node->x = x; + node->next=NULL; if (!front) - front = node; + {front = node; + rear=node;} else { rear->next = node; rear = node; @@ -31,6 +33,7 @@ void pop() else { node = front->next; + free(front); front = node; } } @@ -39,21 +42,23 @@ void search(int x) alfaptr node = front; int counter = 0; while (node) - if (node->x == x) - printf("%d", counter); - else { + {if (node->x == x) + printf("%d ", counter); + else if(node->next==NULL){ printf("ERROR2"); break; } - node = node->next; + counter++; + node = node->next;} } void rpop() {//pop last element alfaptr node = front; - while (node) + while (node->next->next) node = node->next; free(rear); rear = node; + //printf("%d",rear->x); } void set() @@ -66,16 +71,19 @@ void set() int size() { alfaptr node = front; - int count; + int count=0; while (node) - count++;node = node->next; + { + node = node->next; + count++; + } return count; } void show() { - if (!front) { - for (int i = 0; i < MAX_SIZE; i++) + if (front) { + for (int i = 0; i < size(); i++) printf("%d ", arr[i]); } else @@ -88,7 +96,7 @@ int average() { alfaptr node = front; - int sum = 0, count; + int sum = 0, count=0; while (node) { sum += node->x; count++; @@ -97,17 +105,16 @@ int average() return sum / count; } -void main() -{ - int cmd; - long long int x; +int main() +{ int cmd; + int x; while (true) { scanf("%d", &cmd); switch (cmd) { case 1://push - scanf("%lld", &x); + scanf("%d", &x); push(x); break; case 2://pop @@ -117,7 +124,7 @@ void main() rpop(); break; case 4://search - scanf("%lld", &x); + scanf("%d", &x); search(x); break; case 5://set @@ -133,4 +140,4 @@ void main() exit(0); } } -} \ No newline at end of file +} diff --git a/8.cpp b/8.cpp index d851551..eb6a4a0 100644 --- a/8.cpp +++ b/8.cpp @@ -1,6 +1,6 @@ #include const char * f(const char **p) { - auto q = (p + sizeof(char))[1]; + auto const char* q = (p + sizeof(char))[1]; return q; } int main() {