Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug #26

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions 1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

using namespace std;

long long *b;

long long int factorial(int n)
{
return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
Expand All @@ -15,7 +13,7 @@ long long int *producingTheFactorialFractions()
{
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);
}
Expand All @@ -35,10 +33,11 @@ int main()
{

long long int *a;
a = producingTheFactorialFractions();

checkZeros(a);
for (int i = 0; i < 10; i++)
{
a = producingTheFactorialFractions();
cout << a[i] << endl;
}
delete a;
Expand Down
8 changes: 4 additions & 4 deletions 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
85 changes: 65 additions & 20 deletions 3.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 200
int arr[MAX_SIZE];
long long arr[MAX_SIZE];

typedef struct alfa * alfaptr;
typedef struct alfa* alfaptr;

struct alfa {
long long x;
Expand All @@ -15,11 +15,25 @@ void push(int x)
alfaptr node;
node = (alfaptr)malloc(sizeof(struct alfa));
node->x = x;
if (!front)
node->next = NULL;

if (!front) {
front = node;

rear = front;
rear->next = NULL;
}




else {
//printf("sala,%lld", rear->x);
rear->next = node;
rear = node;

rear->next = NULL;
//printf("sala,%lld", rear->x);
}
}

Expand All @@ -36,16 +50,22 @@ void pop()
}
void search(int x)
{
int y = 0;
alfaptr node = front;
int counter = 0;
while (node)
if (node->x == x)
while (node) {
if (node->x == x) {
printf("%d", counter);
else {
printf("ERROR2");
break;
y = 1;
}
node = node->next;
}
if (y == 0) {

printf("eroe 2");

}

}

void rpop() {//pop last element
Expand All @@ -58,25 +78,49 @@ void rpop() {//pop last element

void set()
{
int j = 0;
long long m;

alfaptr node = front;
for (int i = 0; i < MAX_SIZE && node; i++, node = node->next)



for (int i = 0; node != NULL; i++, node = node->next) {
arr[i] = node->x;

printf("%lld ", arr[i]);

}

}

int size()
{
alfaptr node = front;
int count;
while (node)
count++;node = node->next;
int count = 0;
while (node) {
count++;
node = node->next;
// printf("%lld", node);
}

return count;
}

void show()
{
if (!front) {
for (int i = 0; i < MAX_SIZE; i++)
printf("%d ", arr[i]);
if (front) {
alfaptr node = front;

for (int i = 0; node != NULL; i++) {


printf("%lld ", arr[i]);

node = node->next;
}


}
else
{
Expand All @@ -88,8 +132,9 @@ int average()
{

alfaptr node = front;
int sum = 0, count;
while (node) {
long long sum = 0;
int count = 0;
while (node != NULL) {
sum += node->x;
count++;
node = node->next;
Expand All @@ -103,11 +148,11 @@ void main()
long long int x;
while (true)
{
scanf("%d", &cmd);
scanf_s("%d", &cmd);
switch (cmd)
{
case 1://push
scanf("%lld", &x);
scanf_s("%lld", &x);
push(x);
break;
case 2://pop
Expand All @@ -117,7 +162,7 @@ void main()
rpop();
break;
case 4://search
scanf("%lld", &x);
scanf_s("%lld", &x);
search(x);
break;
case 5://set
Expand Down
3 changes: 2 additions & 1 deletion 4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ int main()
float *ptr2 = ptr1 + 3;
printf("%f", *ptr2 - *ptr1);
return 0;
}
}
// addres aray copy shod dar pointer;
3 changes: 2 additions & 1 deletion 5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ int main()
printf("%d\n", (*ptr2 - *ptr1));
printf("%c", (char)(*ptr2 - *ptr1));
return 0;
}
}
//dar khat aval akhtelaf ar[0]-ar[5] va dar khat dovom ekhtelaf adrese khane ha
1 change: 1 addition & 0 deletions 6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ int main()
printf("%d\n", a);
return 0;
}
// add rese a ro be char constant kar bad barabare x gharar dad
3 changes: 2 additions & 1 deletion 7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ int main()
p += 2;
printf("%d", *p);
return 0;
}
}
// meghdar arr[4]
1 change: 1 addition & 0 deletions 8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ int main() {
printf("%c%c ", *f(str), *(f(str) + 1));
printf("%c%c%c%c\n", **str, *(*(str + 1) + 1), *((str + 2)[-1] + 1), **&*(&str[-1] + 1));
}
//khat aval harf w va dar dowoi harf y