forked from mehtimsv/ApLabGitPractice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
50 lines (39 loc) · 1 KB
/
1.cpp
File metadata and controls
50 lines (39 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#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()
{
long long int* b = new long long int[10]; //functionbs can't return arrays in c++.in order to return the array by function,we can use dynamically allocated array
for (int i = 9; i >= 0; i--) // the size of b is 10 so the last element of it, is b[9] ---> i should be 9 at first
{
b[i] = (long long int)pow(factorial(10), 2) / (i + 1); //cast to long long int. because the outputs are very long.
}
return b;
}
void checkZeros(long long* a)
{
for (int i = 9; i >= 0; i--)
{
if (a[i] == 0) //to compare two thing we should use two =.
cout << "Zero Found" << endl;
}
}
int main()
{
long long int* a;
a = producingTheFactorialFractions();
checkZeros(a);
for (int i = 0; i < 10; i++)
{
cout << a[i] << endl;
}
delete a;
cout<<"hello";
cout<<"Bye";
}