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 #52

Open
wants to merge 1 commit 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
18 changes: 9 additions & 9 deletions 1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@

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()
long long int* producingTheFactorialFractions()
{
long long b[10];
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);
}
return b;
}

void checkZeros(long long *a)
void checkZeros(long long* 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;
long long int* a;
a = producingTheFactorialFractions();
checkZeros(a);
for (int i = 0; i < 10; i++)
Expand All @@ -43,8 +43,8 @@ int main()
}
delete a;

cout<<"hello";
cout<<"Bye";
cout << "hello";
cout << "Bye";


}
10 changes: 5 additions & 5 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 All @@ -23,5 +23,5 @@ int main() {
};
char findIt;
cin >> findIt;
cout << countAllSpecificChars(sArr, 4, findIt);
cout << countAllSpecificChars(sArr, 4,findIt);
}
17 changes: 11 additions & 6 deletions 3.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable:4996)
#define MAX_SIZE 200
int arr[MAX_SIZE];

typedef struct alfa * alfaptr;
//do ta countash moshkel dasht


typedef struct alfa* alfaptr;

struct alfa {
long long x;
Expand Down Expand Up @@ -45,7 +49,7 @@ void search(int x)
printf("ERROR2");
break;
}
node = node->next;
node = node->next;
}

void rpop() {//pop last element
Expand All @@ -66,9 +70,9 @@ void set()
int size()
{
alfaptr node = front;
int count;
int count = 0;
while (node)
count++;node = node->next;
count++; node = node->next;
return count;
}

Expand All @@ -88,7 +92,8 @@ int average()
{

alfaptr node = front;
int sum = 0, count;
int sum = 0;
int count = 0;
while (node) {
sum += node->x;
count++;
Expand All @@ -97,7 +102,7 @@ int average()
return sum / count;
}

void main()
int main()
{
int cmd;
long long int x;
Expand Down
5 changes: 3 additions & 2 deletions 4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
int main()
{
float arr[5] = { 12.5, 10.0, 13.5, 90.5, 0.5 };
float *ptr1 = &arr[0];
float *ptr2 = ptr1 + 3;
float* ptr1 = &arr[0];
float* ptr2 = ptr1 + 3;
printf("%f", *ptr2 - *ptr1);
return 0;
//78.0000 = 90.5-12.5
}
2 changes: 2 additions & 0 deletions 5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ int main()
int *ptr1 = arr;
int *ptr2 = arr + 5;
printf("%d\n", (*ptr2 - *ptr1));
//50
printf("%c", (char)(*ptr2 - *ptr1));
//chizi ke code ascci an 50 ast ro print mikone
return 0;
}
11 changes: 9 additions & 2 deletions 6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
int main()
{
int a;
char *x;
x = (char *)&a;
char* x;
// alan char* x be adress a ehshare mikone va ba x[0] byte avalesho be 1 tabdil mikone ke baes mishe addademon avaz she

//summary: the code is gibberish and the C language doesn't define what this program will do.
//It may crash, print any value or print no value at all.
//Pondering about why it behaves in a certain way ***isn't meaningful practice.*** Instead focus on learning how to avoid undefined behavior bugs.

//inam ye shakhsi to stackoverflow neveshte bood
x = (char*)&a;
a = 512;
x[0] = 1;
printf("%d\n", a);
Expand Down
7 changes: 5 additions & 2 deletions 7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
int main()
{
int arr[] = { 1, 2, 3, 4, 5 };
int *p = arr;
++*p;
int* p = arr;
// ++* p meghda *p ra ye dane ziad mikone
++* p;
//printf("%d", *p) tebgh bala age *p ra print konim 1 yedone ziad shode va addad 2 baraye me print mishe
// p+= 2 be baes mishe p 2 ta khone dar array jelo bere va adda 3 ke to khoney sevome ro print begire
p += 2;
printf("%d", *p);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion 8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ 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));


//Be WooW

}