Skip to content
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
38 changes: 27 additions & 11 deletions 1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,41 @@

using namespace std;

long long *b;
long double *b;

long long int factorial(int n)
{
return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}

long long int *producingTheFactorialFractions()
long double *producingTheFactorialFractions()
{
long long b[10];
// memory allocation
b = new long double[10];

for (int i = 10; i >= 0; i--)
// 10 -> 9
for (int i = 9; i >= 0; i--)
{
b[i] += (int)pow(factorial(10), 2.0) / (i + 1);
// equal
b[i] = (long double)(pow(factorial(10), 2.0) / (i + 1));
}
return b;
}

void checkZeros(long long *a)
void checkZeros(long double *a)
{
for (int i = 9; i >= 0; i--)
{
if (a[i] = 0)
// equality oprator
if (a[i] == 0)
cout << "Zero Found" << endl;
}
}

int main()
{

long long int *a;
long double *a;
a = producingTheFactorialFractions();
checkZeros(a);
for (int i = 0; i < 10; i++)
Expand All @@ -43,8 +47,20 @@ int main()
}
delete a;

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


}
//javab
// 1.31682e+013
// 6.58409e+012
// 4.3894e+012
// 3.29205e+012
// 2.63364e+012
// 2.1947e+012
// 1.88117e+012
// 1.64602e+012
// 1.46313e+012
// 1.31682e+012
// helloBye
32 changes: 19 additions & 13 deletions 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@
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)
// if the jth char of the string is the specific char
if (sArr[i][j] = specificChar)
count++;
int countAllSpecificChars(string sArr[], int arrLength, char specificChar)
{
int count = 0; // intial value = 0
for (int i = 0; i < arrLength; i++) //< arrlength not eqaul
{
for (int j = 0; j < sArr[i].size(); j++) //< arrlength not eqaul
{ // if the jth char of the string is the specific char
if (sArr[i][j] == specificChar) // equality oprator
{
count += 1;
}
}
}
return count;
}

int main() {
int main()
{
string sArr[4] = {
"I am",
"in",
"ap",
"class"
};
"I am",
"in",
"ap",
"class"};
char findIt;
cin >> findIt;
cout << countAllSpecificChars(sArr, 4, findIt);
Expand Down
5 changes: 4 additions & 1 deletion 4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ int main()
float *ptr2 = ptr1 + 3;
printf("%f", *ptr2 - *ptr1);
return 0;
}
}


//78.000000 90.5 - 12.5
8 changes: 5 additions & 3 deletions 5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ int main()
int arr[] = { 10, 20, 30, 40, 50, 60 };
int *ptr1 = arr;
int *ptr2 = arr + 5;
printf("%d\n", (*ptr2 - *ptr1));
printf("%c", (char)(*ptr2 - *ptr1));
printf("%d\n", (*ptr2 - *ptr1)); //60-10
printf("%c", (char)(*ptr2 - *ptr1)); //عدد اسکی 50
return 0;
}
}
//50
//2
2 changes: 1 addition & 1 deletion 6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ int main()
x = (char *)&a;
a = 512;
x[0] = 1;
printf("%d\n", a);
printf("%d\n", a); //513
return 0;
}
8 changes: 4 additions & 4 deletions 7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
int main()
{
int arr[] = { 1, 2, 3, 4, 5 };
int *p = arr;
++*p;
p += 2;
printf("%d", *p);
int *p = arr; //p = 1
++*p; //p = 2
p += 2; //p = 3
printf("%d", *p);
return 0;
}
15 changes: 7 additions & 8 deletions 8.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include<stdio.h>
const char * f(const char **p) {
#include <stdio.h>
const char *f(const char **p)
{
auto q = (p + sizeof(char))[1];
return q;
}
int main() {
const char * str[] = { "Wish","You","Best",":D" };
int main()
{
const char *str[] = {"Wish", "You", "Best", ":D"};
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));



printf("%c%c%c%c\n", **str, *(*(str + 1) + 1), *((str + 2)[-1] + 1), **&*(&str[-1] + 1)); // Be WooW
}