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
94 changes: 68 additions & 26 deletions 1.cpp
Original file line number Diff line number Diff line change
@@ -1,50 +1,92 @@
#include <iostream>
#include <string>
#include <math.h>

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 <iostream>
//// uncomment to disable assert()
//// #define NDEBUG
//#include <cassert>
//// Use (void) to silent unused warnings.
//#define assertm(exp, msg) assert(((void)msg, exp))
//#include <string>
//#include <math.h>
//
//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;
//
//}




}
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 @@ -24,4 +24,4 @@ int main() {
char findIt;
cin >> findIt;
cout << countAllSpecificChars(sArr, 4, findIt);
}
}
45 changes: 26 additions & 19 deletions 3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -31,6 +33,7 @@ void pop()
else
{
node = front->next;
free(front);
front = node;
}
}
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -88,7 +96,7 @@ int average()
{

alfaptr node = front;
int sum = 0, count;
int sum = 0, count=0;
while (node) {
sum += node->x;
count++;
Expand All @@ -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
Expand All @@ -117,7 +124,7 @@ void main()
rpop();
break;
case 4://search
scanf("%lld", &x);
scanf("%d", &x);
search(x);
break;
case 5://set
Expand All @@ -133,4 +140,4 @@ void main()
exit(0);
}
}
}
}
2 changes: 1 addition & 1 deletion 8.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include<stdio.h>
const char * f(const char **p) {
auto q = (p + sizeof(char))[1];
auto const char* q = (p + sizeof(char))[1];
return q;
}
int main() {
Expand Down