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
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW64-2.0\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
25 changes: 11 additions & 14 deletions 1.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
#include <iostream>
#include <string>
#include <math.h>
#include <cmath>

using namespace std;

long long *b;
unsigned long long *b;

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

long long int *producingTheFactorialFractions()
unsigned long long int *producingTheFactorialFractions()
{
long long b[10];
b = new unsigned long long[10];

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

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

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


cout << "hello";
cout << "Bye";
}
Binary file added 1.exe
Binary file not shown.
29 changes: 17 additions & 12 deletions 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
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)
int countAllSpecificChars(string sArr[], int arrLength, char specificChar)
{
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)
count++;
}
}
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
Binary file added 2.exe
Binary file not shown.
130 changes: 87 additions & 43 deletions 3.cpp
Original file line number Diff line number Diff line change
@@ -1,59 +1,97 @@
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;
#define MAX_SIZE 200
int arr[MAX_SIZE];

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

struct alfa {
long long x;
struct alfa
{
int x;
alfaptr next;
};

alfaptr rear = NULL, front = NULL;

void push(int x)
{
alfaptr node;
node = (alfaptr)malloc(sizeof(struct alfa));
node = new alfa;
node->x = x;
node->next = NULL;
if (!front)
{
front = node;
else {
rear = node;
}
else
{
rear->next = node;
rear = node;
}
}

void pop()
{
alfaptr node;
if (!front)
printf("ERROR1");
cout << "ERROR 1" << endl;
else
{
node = front->next;
front = node;
if (front == rear)
{
delete front;
front = NULL;
rear = NULL;
}
else
{
alfaptr node;
node = front->next;
delete front;
front = node;
}
}
}

void search(int x)
{
alfaptr node = front;
int counter = 0;
int s_counter = 0;
while (node)
{
if (node->x == x)
printf("%d", counter);
else {
printf("ERROR2");
break;
{
cout << s_counter << endl;
return;
}
node = node->next;
else
{
s_counter++;
node = node->next;
}
}
cout << "ERROR 2" << endl;
}

void rpop() {//pop last element
alfaptr node = front;
while (node)
node = node->next;
free(rear);
rear = node;
void rpop()
{ // pop last element
if (rear == front)
{
delete front;
front = NULL;
rear = NULL;
}
else
{
alfaptr node = front;
while (node->next->next)
{
node = node->next;
}
delete rear;
rear = node;
rear->next = NULL;
}
}

void set()
Expand All @@ -66,68 +104,74 @@ void set()
int size()
{
alfaptr node = front;
int count;
int counter = 0;
while (node)
count++;node = node->next;
return count;
{
counter++;
node = node->next;
}
node = node->next;
return counter;
}

void show()
{
if (!front) {
if (!front)
{
for (int i = 0; i < MAX_SIZE; i++)
printf("%d ", arr[i]);
cout << arr[i] << endl;
}
else
{
printf("ERROR3");
cout << "ERROR3" << endl;
}
}

int average()
{

alfaptr node = front;
int sum = 0, count;
while (node) {
int sum = 0, count = 0;
while (node)
{
sum += node->x;
count++;
node = node->next;
}
return sum / count;
}

void main()
int main()
{
int cmd;
long long int x;
while (true)
{
scanf("%d", &cmd);
cin >> cmd;
switch (cmd)
{
case 1://push
scanf("%lld", &x);
case 1: // push
cin >> x;
push(x);
break;
case 2://pop
case 2: // pop
pop();
break;
case 3://rpop
case 3: // rpop
rpop();
break;
case 4://search
scanf("%lld", &x);
case 4: // search
cin >> x;
search(x);
break;
case 5://set
case 5: // set
set();
break;
case 6://show
case 6: // show
show();
break;
case 7://size
printf("%d", size());
case 7: // size
cout << size() << endl;
break;
case 10:
exit(0);
Expand Down
Binary file added 3.exe
Binary file not shown.
7 changes: 4 additions & 3 deletions 4.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include<stdio.h>
#include <iostream>
using namespace std;
int main()
{
float arr[5] = { 12.5, 10.0, 13.5, 90.5, 0.5 };
float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5};
float *ptr1 = &arr[0];
float *ptr2 = ptr1 + 3;
printf("%f", *ptr2 - *ptr1);
cout << (*ptr2 - *ptr1) << endl;
return 0;
}
Binary file added 4.exe
Binary file not shown.
10 changes: 6 additions & 4 deletions 5.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include<stdio.h>
#include <iostream>
using namespace std;

int main()
{
int arr[] = { 10, 20, 30, 40, 50, 60 };
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));
cout << (*ptr2 - *ptr1) << endl;
cout << (char)(*ptr2 - *ptr1) << endl;
return 0;
}
Binary file added 5.exe
Binary file not shown.
6 changes: 4 additions & 2 deletions 6.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include<stdio.h>
#include <iostream>
using namespace std;

int main()
{
int a;
char *x;
x = (char *)&a;
a = 512;
x[0] = 1;
printf("%d\n", a);
cout<<a<<endl;
return 0;
}
Binary file added 6.exe
Binary file not shown.
Loading