### remove old stuff

master
parent f4fa9cdf8e
commit 74d8503a20
557 changed files with 0 additions and 23552 deletions

#### 70 c++/11_Numerical_Problems/C++ Perform to a 2D FFT Inplace Given a Complex 2D Array.cpp Unescape Escape View File

 `@ -1,70 +0,0 @@` `/*This is a C++ Program to perform 2D FFT. A fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform (DFT) and its inverse. Fourier analysis converts time (or space) to frequency and vice versa; an FFT rapidly computes such transformations by factorizing the DFT matrix into a product of sparse (mostly zero) factors.*/` ``` ``` `#include ` `#include ` ``` ``` `using namespace std;` ``` ``` `#define PI 3.14159265` `int n;` ``` ``` `int main(int argc, char **argv)` `{` ` cout << "Enter the size: ";` ` cin >> n;` ` double inputData[n][n];` ` cout << "Enter the 2D elements ";` ` for (int i = 0; i < n; i++)` ` for (int j = 0; j < n; j++)` ` cin >> inputData[i][j];` ` double realOut[n][n];` ` double imagOut[n][n];` ` double amplitudeOut[n][n];` ` int height = n;` ` int width = n;` ``` // Two outer loops iterate on output data. ``` ` for (int yWave = 0; yWave < height; yWave++)` ` {` ` for (int xWave = 0; xWave < width; xWave++)` ` {` ``` // Two inner loops iterate on input data. ``` ` for (int ySpace = 0; ySpace < height; ySpace++)` ` {` ` for (int xSpace = 0; xSpace < width; xSpace++)` ` {` ``` // Compute real, imag, and ampltude. ``` ` realOut[yWave][xWave] += (inputData[ySpace][xSpace] * cos(` ` 2 * PI * ((1.0 * xWave * xSpace / width) + (1.0` ` * yWave * ySpace / height)))) / sqrt(` ` width * height);` ` imagOut[yWave][xWave] -= (inputData[ySpace][xSpace] * sin(` ` 2 * PI * ((1.0 * xWave * xSpace / width) + (1.0` ` * yWave * ySpace / height)))) / sqrt(` ` width * height);` ` amplitudeOut[yWave][xWave] = sqrt(` ` realOut[yWave][xWave] * realOut[yWave][xWave]` ` + imagOut[yWave][xWave]` ` * imagOut[yWave][xWave]);` ` }` ` cout << realOut[yWave][xWave] << " + " << imagOut[yWave][xWave]` ` << " i (" << amplitudeOut[yWave][xWave] << ")\n";` ` }` ` }` ` }` `}` ``` ``` ```/* ``` `Enter the size:` `2` `Enter the 2D elements` `2 3` `4 2` ``` ``` `2.5 + 0.0 i` `5.5 + 0.0 i` `-0.5 + -1.8369701987210297E-16 i` `0.5 + -3.0616169978683826E-16 i` `2.5 + 0.0 i` `-0.5 + -3.6739403974420594E-16 i` `-0.5 + -1.8369701987210297E-16 i` `-1.5 + -1.8369701987210297E-16 i`

#### 40 c++/11_Numerical_Problems/C++ Program to Check Multiplicability of Two Matrices.cpp Unescape Escape View File

 `@ -1,40 +0,0 @@` `#include` `#include` `#include` ``` ``` `using namespace std;` ``` ``` `int main(int argc, char **argv)` `{` ` cout<<"Enter the dimension of the matrix:\n ";` ` int rowA;` ` cin>>rowA;` ` int colA;` ` cin>>colA;` ` cout<<"Enter the dimension of the other matrix:\n ";` ` int rowB;` ` cin>>rowB;` ` int colB;` ` cin>>colB;` ` if(colA == rowB)` ` {` ` cout<<"Matrices are multipilcable";` ` }` ` else` ` {` ` cout<<"Matrices are not multipilcable";` ` }` `}` ``` ``` ```/* ``` `Enter the dimension of the matrix:` ` 2 4` `Enter the dimension of the other matrix:` ` 2 5` `Matrices are not multipilcable` ``` ``` `Enter the dimension of the matrix:` ` 4 5` `Enter the dimension of the other matrix:` ` 5 6` `Matrices are multipilcable`

#### 76 c++/11_Numerical_Problems/C++ Program to Check if a Matrix is Invertible.cpp Unescape Escape View File

 `@ -1,76 +0,0 @@` `#include` `#include` `#include` ``` ``` `using namespace std;` `double d = 0;` `double det(int n, double mat[10][10]);` `double det(int n, double mat[10][10])` `{` ` double submat[10][10];` ` if (n == 2)` ` return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1]));` ` else` ` {` ` for (int c = 0; c < n; c++)` ` {` ``` int subi = 0; //submatrix's i value ``` ` for (int i = 1; i < n; i++)` ` {` ` int subj = 0;` ` for (int j = 0; j < n; j++)` ` {` ` if (j == c)` ` continue;` ` submat[subi][subj] = mat[i][j];` ` subj++;` ` }` ` subi++;` ` }` ` d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat));` ` }` ` }` ` return d;` `}` `int main(int argc, char **argv)` `{` ` cout << "Enter the dimension of the matrix:\n";` ` int n;` ` cin >> n;` ` double mat[10][10];` ` cout << "Enter the elements of the matrix:\n";` ` for (int i = 0; i < n; i++)` ` {` ` for (int j = 0; j < n; j++)` ` {` ` cin >> mat[j][i];` ` }` ` }` ` if (det(n, mat) != 0)` ` {` ` cout << "The given matrix is invertible";` ` }` ` else` ` {` ` cout << "The given matrix is not invertible";` ` }` `}` ``` ``` ```/* ``` `Enter the dimension of the matrix:` `3` `Enter the elements of the matrix:` `1 2 3` `4 5 6` `7 8 9` `The given matrix is not invertible` ``` ``` `Enter the dimension of the matrix:` `5` `Enter the elements of the matrix:` `1 2 3 4 5` `6 7 8 9 0` `0 9 8 7 6` `5 4 3 2 1` `1 3 5 7 9` `The given matrix is invertible`

#### 54 c++/11_Numerical_Problems/C++ Program to Check if it is a Sparse Matrix.cpp Unescape Escape View File

 `@ -1,54 +0,0 @@` `#include ` `#include ` ``` ``` `using namespace std;` `int main(int argc, char **argv)` `{` ` cout<<"Enter the dimensions of the matrix: ";` ` int m, n;` ` cin>>m>>n;` ` double mat[m][n];` ` int zeros = 0;` ` cout<<"Enter the elements of the matrix: ";` ` for(int i=0; i>mat[i][j];` ` if(mat[i][j] == 0)` ` {` ` zeros++;` ` }` ` }` ` }` ` if(zeros > (m*n)/2)` ` {` ` cout<<"The matrix is a sparse matrix";` ` }` ` else` ` {` ` cout<<"The matrix is not a sparse matrix";` ` }` `}` ``` ``` ```/* ``` `Enter the dimensions of the matrix:` `3 3` ``` ``` `Enter the elements of the matrix:` `1 2 3` `4 5 6` `0 0 0` ``` ``` `The matrix is not a sparse matrix` ``` ``` ``` ``` `Enter the dimensions of the matrix:` `3 3` ``` ``` `Enter the elements of the matrix:` `1 1 0` `0 0 1` `1 0 0` ``` ``` `The matrix is a sparse matrix`

#### 65 c++/11_Numerical_Problems/C++ Program to Compute DFT Coefficients Directly.cpp Unescape Escape View File

 `@ -1,65 +0,0 @@` `/*This is a C++ Program to compute the coefficients of the DFT (Discrete Fourier Transform) directly. In mathematics, the discrete Fourier transform (DFT) converts a finite list of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids, ordered by their frequencies, that has those same sample values. It can be said to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.*/` ``` ``` `#include` `#include` ``` ``` `using namespace std;` ``` ``` `#define PI 3.14159265` ``` ``` `class DFT_Coefficient` `{` `public:` ` double real, img;` ` DFT_Coefficient()` ` {` ` real = 0.0;` ` img = 0.0;` ` }` `};` `int main(int argc, char **argv)` `{` ` int N = 10;` ` cout << "Calculation DFT Coefficients\n";` ` cout << "Enter the coefficient of simple linear function:\n";` ` cout << "ax + by = c\n";` ` double a, b, c;` ` cin >> a >> b >> c;` ` double function[N];` ` for (int i = 0; i < N; i++)` ` {` ` function[i] = (((a * (double) i) + (b * (double) i)) - c);` ``` //System.out.print( " "+function[i] + " "); ``` ` }` ` cout << "Enter the max K value: ";` ` int k;` ` cin >> k;` ` double cosine[N];` ` double sine[N];` ` for (int i = 0; i < N; i++)` ` {` ` cosine[i] = cos((2 * i * k * PI) / N);` ` sine[i] = sin((2 * i * k * PI) / N);` ` }` ` DFT_Coefficient dft_val;` ` cout << "The coefficients are: ";` ` for (int i = 0; i < N; i++)` ` {` ` dft_val.real += function[i] * cosine[i];` ` dft_val.img += function[i] * sine[i];` ` }` ` cout << "(" << dft_val.real << ") - " << "(" << dft_val.img << " i)";` `}` ``` ``` ```/* ``` `Calculation DFT Coefficients` `Enter the coefficient of simple linear funtion:` `ax + by = c` `1 2 3` `Enter the max K value:` `2` `The coefficients are: (-15) - (-20.6457 i)` ``` ``` `------------------` `(program exited with code: 0)` `Press return to continue`

#### 69 c++/11_Numerical_Problems/C++ Program to Compute Determinant of a Matrix.cpp Unescape Escape View File

 `@ -1,69 +0,0 @@` `#include` `#include` `#include` ``` ``` `using namespace std;` `double d = 0;` `double det(int n, double mat[10][10]);` `double det(int n, double mat[10][10])` `{` ` double submat[10][10];` ` if (n == 2)` ` return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1]));` ` else` ` {` ` for (int c = 0; c < n; c++)` ` {` ``` int subi = 0; //submatrix's i value ``` ` for (int i = 1; i < n; i++)` ` {` ` int subj = 0;` ` for (int j = 0; j < n; j++)` ` {` ` if (j == c)` ` continue;` ` submat[subi][subj] = mat[i][j];` ` subj++;` ` }` ` subi++;` ` }` ` d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat));` ` }` ` }` ` return d;` `}` `int main(int argc, char **argv)` `{` ` cout << "Enter the dimension of the matrix:\n";` ` int n;` ` cin >> n;` ` double mat[10][10];` ` cout << "Enter the elements of the matrix:\n";` ` for (int i = 0; i < n; i++)` ` {` ` for (int j = 0; j < n; j++)` ` {` ` cin >> mat[j][i];` ` }` ` }` ` cout << "The determinant of the given matrix is: " << det(n, mat);` ` return 0;` `}` ``` ``` ```/* ``` `Enter the dimension of the matrix:` `3` `Enter the elements of the matrix:` `3 5 2` `8 4 8` `2 4 7` `The determinant of the given matrix is: -164` ``` ``` `Enter the dimension of the matrix:` `4` `Enter the elements of the matrix:` `9 5 2 5` `9 5 3 7` `6 5 4 8` `1 5 3 7` `The determinant of the given matrix is: 0`

#### 84 c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using Naive Approach.cpp Unescape Escape View File

 `@ -1,84 +0,0 @@` `/*This is a C++ Program to perform Discrete Fourier Transform using Naive approach. In mathematics, the discrete Fourier transform (DFT) converts a finite list of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids, ordered by their frequencies, that has those same sample values. It can be said to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.*/` ``` ``` `#include` `#include` ``` ``` `using namespace std;` ``` ``` `#define PI 3.14159265` ``` ``` `class DFT_Coefficient` `{` `public:` ` double real, img;` ` DFT_Coefficient()` ` {` ` real = 0.0;` ` img = 0.0;` ` }` `};` `int main(int argc, char **argv)` `{` ` int N = 10;` ` cout << "Discrete Fourier Transform using naive method\n";` ` cout << "Enter the coefficient of simple linear function:\n";` ` cout << "ax + by = c\n";` ` double a, b, c;` ` cin >> a >> b >> c;` ` double function[N];` ` for (int i = 0; i < N; i++)` ` {` ` function[i] = (((a * (double) i) + (b * (double) i)) - c);` ``` //System.out.print( " "+function[i] + " "); ``` ` }` ` cout << "Enter the max K value: ";` ` int k;` ` cin >> k;` ` double cosine[N];` ` double sine[N];` ` for (int i = 0; i < N; i++)` ` {` ` cosine[i] = cos((2 * i * k * PI) / N);` ` sine[i] = sin((2 * i * k * PI) / N);` ` }` ` DFT_Coefficient dft_val[k];` ` cout << "The coefficients are: ";` ` for (int j = 0; j < k; j++)` ` {` ` for (int i = 0; i < N; i++)` ` {` ` dft_val[j].real += function[i] * cosine[i];` ` dft_val[j].img += function[i] * sine[i];` ` }` ` cout << "(" << dft_val[j].real << ") - " << "(" << dft_val[j].img << " i)\n";` ` }` `}` ``` ``` ```/* ``` ``` ``` `Discrete Fourier Transform using naive method` `Enter the coefficient of simple linear function:` `ax + by = c` `1 2 3` `Enter the max K value: 20` `The coefficients are:` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)` `(105) - (-1.03386e-005 i)`

#### 73 c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using the Fast Fourier Transform Approach.cpp Unescape Escape View File

 `@ -1,73 +0,0 @@` `/*This is a C++ Program to perform Fast Fourier Transform. A fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform (DFT) and its inverse. Fourier analysis converts time (or space) to frequency and vice versa; an FFT rapidly computes such transformations by factorizing the DFT matrix into a product of sparse (mostly zero) factors.*/` ``` ``` `#include ` `#include ` `#include ` `#include ` `using namespace std;` ``` ``` `unsigned int bitReverse(unsigned int x, int log2n)` ``` ``` `{` ` int n = 0;` ` int mask = 0x1;` ` for (int i = 0; i < log2n; i++)` ` {` ` n <<= 1;` ` n |= (x & 1);` ` x >>= 1;` ` }` ` return n;` `}` `const double PI = 3.1415926536;` `template` `void fft(Iter_T a, Iter_T b, int log2n)` `{` ` typedef typename iterator_traits::value_type complex;` ` const complex J(0, 1);` ` int n = 1 << log2n;` ` for (unsigned int i = 0; i < n; ++i)` ` {` ` b[bitReverse(i, log2n)] = a[i];` ` }` ` for (int s = 1; s <= log2n; ++s)` ` {` ` int m = 1 << s;` ` int m2 = m >> 1;` ` complex w(1, 0);` ` complex wm = exp(-J * (PI / m2));` ` for (int j = 0; j < m2; ++j)` ` {` ` for (int k = j; k < n; k += m)` ` {` ` complex t = w * b[k + m2];` ` complex u = b[k];` ` b[k] = u + t;` ` b[k + m2] = u - t;` ` }` ` w *= wm;` ` }` ` }` `}` `int main(int argc, char **argv)` `{` ` typedef complex cx;` ` cx a[] = { cx(0, 0), cx(1, 1), cx(3, 3), cx(4, 4), cx(4, 4), cx(3, 3), cx(` ` 1, 1), cx(0, 0)` ` };` ` cx b[8];` ` fft(a, b, 3);` ` for (int i = 0; i < 8; ++i)` ` cout << b[i] << "\n";` `}` ``` ``` ```/* ``` ``` ``` `(16,16)` `(-4.82843,-11.6569)` `(0,0)` `(-0.343146,0.828427)` `(0,0)` `(0.828427,-0.343146)` `(0,0)` `(-11.6569,-4.82843)`

#### 25 c++/11_Numerical_Problems/C++ Program to Emulate N Dice Roller.cpp Unescape Escape View File

 `@ -1,25 +0,0 @@` `#include ` `#include ` ``` ``` `using namespace std;` ``` ``` `int main(int argc, char **argv)` `{` ` cout << "Enter the number of dice: ";` ` int n;` ` cin >> n;` ` cout << "The values on dice are: ( ";` ` for (int i = 0; i < n; i++)` ` cout << (rand() % 6) + 1<<" ";` ` cout<<")";` `}` ``` ``` ```/* ``` `Enter the number of dice: 5` `The values on dice are: ( 6 6 5 5 6 )` ``` ``` `Enter the number of dice: 1` `The values on dice are: ( 6 )` ``` ``` `Enter the number of dice: 3` `The values on dice are: ( 6 6 5 )`

#### 74 c++/11_Numerical_Problems/C++ Program to Find Basis and Dimension of a Matrix.cpp Unescape Escape View File

 `@ -1,74 +0,0 @@` `#include` `#include` `#include` ``` ``` `using namespace std;` `double d = 0;` `double det(int n, double mat[10][10]);` `double det(int n, double mat[10][10])` `{` ` double submat[10][10];` ` if (n == 2)` ` return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1]));` ` else` ` {` ` for (int c = 0; c < n; c++)` ` {` ``` int subi = 0; //submatrix's i value ``` ` for (int i = 1; i < n; i++)` ` {` ` int subj = 0;` ` for (int j = 0; j < n; j++)` ` {` ` if (j == c)` ` continue;` ` submat[subi][subj] = mat[i][j];` ` subj++;` ` }` ` subi++;` ` }` ` d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat));` ` }` ` }` ` return d;` `}` `int main(int argc, char **argv)` `{` ` cout << "Enter the number of vectors:\n";` ` int n;` ` cin >> n;` ` double mat[10][10];` ` cout << "Enter the vectors one by one:\n";` ` for (int i = 0; i < n; i++)` ` {` ` for (int j = 0; j < n; j++)` ` {` ` cin >> mat[j][i];` ` }` ` }` ` d = det(n, mat);` ` if (d != 0)` ` cout << "The vectors forms the basis of R" << n` ` << " as the determinant is non-zero";` ` else` ` cout << "The vectors doesn't form the basis of R" << n` ` << " as the determinant is zero";` `}` ``` ``` ```/* ``` `Enter the number of vectors:` `3` `Enter the vectors one by one:` `1 2 3` `2 3 4` `3 4 5` `The vectors doesn't form the basis of R3 as the determinant is zero` ``` ``` `Enter the number of vectors:` `4` `Enter the vectors one by one:` `2 3 5 8` `1 6 2 9` `3 4 2 7` `2 5 3 9` `The vectors forms the basis of R4 as the determinant is non-zero`

#### 137 c++/11_Numerical_Problems/C++ Program to Find Closest Pair of Points in an Array.cpp Unescape Escape View File

 `@ -1,137 +0,0 @@` ```/* ``` ` * C++ Program to Find Closest Pair of Points in an Array` ` */` `#include ` `#include ` `#include ` `#include ` `using namespace std;` ``` ``` ```/* ``` ` * Point Declaration` ` */` `struct Point` `{` ` int x, y;` `};` ``` ``` ```/* ``` ` * sort array of points according to X coordinate` ` */` `int compareX(const void* a, const void* b)` `{` ` Point *p1 = (Point *)a, *p2 = (Point *)b;` ` return (p1->x - p2->x);` `}` ```/* ``` ` * sort array of points according to Y coordinate` ` */` `int compareY(const void* a, const void* b)` `{` ` Point *p1 = (Point *)a, *p2 = (Point *)b;` ` return (p1->y - p2->y);` `}` ```/* ``` ` * find the distance between two points` ` */` `float dist(Point p1, Point p2)` `{` ` return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));` `}` ```/* ``` ` * return the smallest distance between two points` ` */` `float small_dist(Point P[], int n)` `{` ` float min = FLT_MAX;` ` for (int i = 0; i < n; ++i)` ` {` ` for (int j = i + 1; j < n; ++j)` ` {` ` if (dist(P[i], P[j]) < min)` ` min = dist(P[i], P[j]);` ` }` ` }` ` return min;` `}` ```/* ``` ` * find the distance beween the closest points of strip of given size` ` */` `float stripClosest(Point strip[], int size, float d)` `{` ` float min = d;` ` for (int i = 0; i < size; ++i)` ` {` ` for (int j = i + 1; j < size && (strip[j].y - strip[i].y) < min; ++j)` ` {` ` if (dist(strip[i],strip[j]) < min)` ` min = dist(strip[i], strip[j]);` ` }` ` }` ` return min;` `}` ```/* ``` ` * find the smallest distance.` ` */` `float closestUtil(Point Px[], Point Py[], int n)` `{` ` if (n <= 3)` ` return small_dist(Px, n);` ` int mid = n / 2;` ` Point midPoint = Px[mid];` ` Point Pyl[mid + 1];` ` Point Pyr[n - mid - 1];` ` int li = 0, ri = 0;` ` for (int i = 0; i < n; i++)` ` {` ` if (Py[i].x <= midPoint.x)` ` Pyl[li++] = Py[i];` ` else` ` Pyr[ri++] = Py[i];` ` }` ` float dl = closestUtil(Px, Pyl, mid);` ` float dr = closestUtil(Px + mid, Pyr, n-mid);` ` float d = min(dl, dr);` ` Point strip[n];` ` int j = 0;` ` for (int i = 0; i < n; i++)` ` {` ` if (abs(Py[i].x - midPoint.x) < d)` ` strip[j] = Py[i], j++;` ` }` ` return min(d, stripClosest(strip, j, d));` `}` ```/* ``` ` * finds the smallest distance` ` */` `float closest(Point P[], int n)` `{` ` Point Px[n];` ` Point Py[n];` ` for (int i = 0; i < n; i++)` ` {` ` Px[i] = P[i];` ` Py[i] = P[i];` ` }` ` qsort(Px, n, sizeof(Point), compareX);` ` qsort(Py, n, sizeof(Point), compareY);` ` return closestUtil(Px, Py, n);` `}` ``` ``` ```/* ``` ` * Main` ` */` `int main()` `{` ` Point P[] = {{2, 3}, {12, 30}, {40, 50}, {5, 1}, {12, 10}, {3, 4}};` ` int n = sizeof(P) / sizeof(P[0]);` ` cout << "The smallest distance is " << closest(P, n);` ` return 0;` `}` ``` ``` ```/* ``` `The smallest distance is 1.41421` ``` ``` `------------------` `(program exited with code: 1)` `Press return to continue`

#### 83 c++/11_Numerical_Problems/C++ Program to Find Factoial of Large Numbers.cpp Unescape Escape View File

 `@ -1,83 +0,0 @@` ```/* ``` ` * C++ Program to Find Factorial of Large Numbers` ` */` `#include ` `#include ` `#include ` `#define ll long long` `using namespace std;` ``` ``` `int fact[101][200] = {0};` ``` ``` ```/* ``` ` * Find Factorial of Large Numbers` ` * fact[i][0] is used to store the number of digits` ` */` `void fact_large(int n)` `{` ` int i;` ` fact[1][0] = 1;` ` fact[1][1] = 1;` ` if (fact[n][0] == 0)` ` {` ` for (i = n - 1; i > 0 ; i--)` ` {` ` if (fact[i][0] != 0)` ` break;` ` }` ` for ( ; i < n; i++)` ` {` ` int j = 1;` ` int carry = 0;` ` int len = fact[i][0];` ` while (len--)` ` {` ` int temp = (i + 1) * fact[i][j] + carry;` ` fact[i + 1][j] = temp % 10;` ` carry = temp / 10;` ` j++;` ` }` ` while (carry > 0)` ` {` ` fact[i + 1][j] = carry % 10;` ` carry /= 10;` ` j++;` ` }` ` fact[i + 1][0] = j - 1;` ` }` ` }` ` for (i = fact[n][0]; i > 0; i--)` ` {` ` cout << fact[n][i];` ` }` ` cout<>n;` ` if (n == 0)` ` break;` ` fact_large(n);` ` }` ` return 0;` `}` ``` ``` ```/* ``` `Enter interger to compute factorial(0 to exit): 100` `93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000` `Enter interger to compute factorial(0 to exit): 50` `30414093201713378043612608166064768844377641568960512000000000000` `Enter interger to compute factorial(0 to exit): 72` `61234458376886086861524070385274672740778091784697328983823014963978384987221689274204160000000000000000` `Enter interger to compute factorial(0 to exit): 0` ``` ``` `------------------` `(program exited with code: 1)` `Press return to continue`

#### 55 c++/11_Numerical_Problems/C++ Program to Find Factoial of a Number using Dynamic Programming.cpp Unescape Escape View File

 `@ -1,55 +0,0 @@` ```/* ``` ` * C++ Program to Find Factorial of a Number using Dynamic Programming` ` */` `#include ` `#include ` `#include ` `#define ll long long` `using namespace std;` ``` ``` `int result[1000] = {0};` ```/* ``` ` * Find Factorial of a Number using Dynamic Programming` ` */` `ll fact_dp(int n)` `{` ` if (n >= 0)` ` {` ` result[0] = 1;` ` for (int i = 1; i <= n; ++i)` ` {` ` result[i] = i * result[i - 1];` ` }` ` return result[n];` ` }` `}` ```/* ``` ` * Main` ` */` `int main()` `{` ` int n;` ` while (1)` ` {` ` cout<<"Enter interger to compute factorial(0 to exit): ";` ` cin>>n;` ` if (n == 0)` ` break;` ` cout<

#### 49 c++/11_Numerical_Problems/C++ Program to Find Factoial of a Number using Iteration.cpp Unescape Escape View File

 `@ -1,49 +0,0 @@` ```/* ``` ` * C++ Program to Find Factorial of a Number using Iteration` ` */` `#include ` `#include ` `#include ` `#define ll long long` `using namespace std;` ```/* ``` ` * Find Factorial of a Number using Iteration` ` */` `ll fact_iter(int n)` `{` ` ll result = 1;` ` for (int i = 1; i <= n; i++)` ` {` ` result *= i;` ` }` ` return result;` `}` ```/* ``` ` * Main` ` */` `int main()` `{` ` int n;` ` while (1)` ` {` ` cout<<"Enter interger to compute factorial(0 to exit): ";` ` cin>>n;` ` if (n == 0)` ` break;` ` cout<

#### 47 c++/11_Numerical_Problems/C++ Program to Find Factorial of a Number using Recursion.cpp Unescape Escape View File

 `@ -1,47 +0,0 @@` ```/* ``` ` * C++ Program to Find Factorial of a Number using Recursion` ` */` `#include ` `#include ` `#include ` `#define ll long long` `using namespace std;` ```/* ``` ` * Find Factorial of a Number using Recursion` ` */` `ll fact_recur(int n)` `{` ` if (n == 0 || n == 1)` ` return 1;` ` else` ` return n * fact_recur(n - 1);` `}` ```/* ``` ` * Main` ` */` `int main()` `{` ` int n;` ` while (1)` ` {` ` cout<<"Enter interger to compute factorial(0 to exit): ";` ` cin>>n;` ` if (n == 0)` ` break;` ` cout<

#### 71 c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Dynamic Programming.cpp Unescape Escape View File

 `@ -1,71 +0,0 @@` ```/* ``` ` * C++ Program to Find Fibonacci Numbers using Dynamic Programming` ` */` `#include ` `#include ` `#include ` `#define ll long long` `using namespace std;` ``` ``` `ll fib[1000] = {0};` ```/* ``` ` * Fibonacci Numbers using Dp` ` */` `ll fibo_dp(int n)` `{` ` fib[1] = 1;` ` fib[2] = 1;` ` if (fib[n] == 0)` ` {` ` for (int j = 3; j <= n; ++j)` ` {` ` if (fib[n] == 0)` ` fib[j] = fib[j - 1] + fib[j - 2];` ` else` ` continue;` ` }` ` }` ` return fib[n];` `}` ``` ``` ```/* ``` ` * Main` ` */` `int main()` `{` ` int n;` ` while (1)` ` {` ` cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): ";` ` cin>>n;` ` if (n == 0)` ` break;` ` cout<

#### 68 c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Iteration.cpp Unescape Escape View File

 `@ -1,68 +0,0 @@` ```/* ``` ` * C++ Program to Find Fibonacci Numbers using Iteration` ` */` `#include ` `#include ` `#include ` `#define ll long long` `using namespace std;` ``` ``` ```/* ``` ` * Iterative function to find Fibonacci Numbers` ` */` `ll fibo_iter(int n)` `{` ` int previous = 1;` ` int current = 1;` ` int next = 1;` ` for (int i = 3; i <= n; ++i)` ` {` ` next = current + previous;` ` previous = current;` ` current = next;` ` }` ` return next;` `}` ```/* ``` ` * Main` ` */` `int main()` `{` ` int n;` ` while (1)` ` {` ` cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): ";` ` cin>>n;` ` if (n == 0)` ` break;` ` cout<

#### 92 c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Matrix Exponentiation.cpp Unescape Escape View File

 `@ -1,92 +0,0 @@` ```/* ``` ` * C++ Program to Find Fibonacci Numbers using Matrix Exponentiation` ` */` `#include ` `#include ` `#include ` `#define ll long long` `using namespace std;` ``` ``` ```/* ``` ` * function to multiply two matrices` ` */` `void multiply(ll F[2][2], ll M[2][2])` `{` ` ll x = F[0][0] * M[0][0] + F[0][1] * M[1][0];` ` ll y = F[0][0] * M[0][1] + F[0][1] * M[1][1];` ` ll z = F[1][0] * M[0][0] + F[1][1] * M[1][0];` ` ll w = F[1][0] * M[0][1] + F[1][1] * M[1][1];` ` F[0][0] = x;` ` F[0][1] = y;` ` F[1][0] = z;` ` F[1][1] = w;` `}` ``` ``` ```/* ``` ` * function to calculate power of a matrix` ` */` `void power(ll F[2][2], int n)` `{` ` if (n == 0 || n == 1)` ` return;` ` ll M[2][2] = {{1,1},{1,0}};` ` power(F, n / 2);` ` multiply(F, F);` ` if (n % 2 != 0)` ` multiply(F, M);` `}` ``` ``` ```/* ``` ` * function that returns nth Fibonacci number` ` */` `ll fibo_matrix(ll n)` `{` ` ll F[2][2] = {{1,1},{1,0}};` ` if (n == 0)` ` return 0;` ` power(F, n - 1);` ` return F[0][0];` `}` ```/* ``` ` * Main` ` */` `int main()` `{` ` int n;` ` while (1)` ` {` ` cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): ";` ` cin>>n;` ` if (n == 0)` ` break;` ` cout<

#### 62 c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Recursion.cpp Unescape Escape View File

 `@ -1,62 +0,0 @@` ```/* ``` ` * C++ Program to Find Fibonacci Numbers using Recursion` ` */` `#include ` `#include ` `#include ` `#define ll long long` `using namespace std;` ``` ``` ```/* ``` ` * Recursive function to find Fibonnaci Numbers` ` */` `ll fibo_recur(int n)` `{` ` if (n == 1 || n == 2)` ` return 1;` ` else` ` return fibo_recur(n - 1) + fibo_recur(n - 2);;` `}` ```/* ``` ` * Main` ` */` `int main()` `{` ` int n;` ` while (1)` ` {` ` cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): ";` ` cin>>n;` ` if (n == 0)` ` break;` ` cout<

#### 35 c++/11_Numerical_Problems/C++ Program to Find GCD of Two Numbers Using Recursive Euclid Algorithm.cpp Unescape Escape View File

 `@ -1,35 +0,0 @@` ```/*This is a C++ Program to find GCD of two numbers using Recursive Euclid Algorithm. In mathematics, the Euclidean algorithm, or Euclid’s algorithm, is a method for computing the greatest common divisor (GCD) of two (usually positive) integers, also known as the greatest common factor (GCF) or highest common factor (HCF). It is named after the Greek mathematician Euclid, who described it in Books VII and X of his Elements. ``` `The GCD of two positive integers is the largest integer that divides both of them without leaving a remainder (the GCD of two integers in general is defined in a more subtle way).` ``` ``` `In its simplest form, Euclid’s algorithm starts with a pair of positive integers, and forms a new pair that consists of the smaller number and the difference between the larger and smaller numbers. The process repeats until the numbers in the pair are equal. That number then is the greatest common divisor of the original pair of integers.` ``` ``` `The main principle is that the GCD does not change if the smaller number is subtracted from the larger number. For example, the GCD of 252 and 105 is exactly the GCD of 147 (= 252 – 105) and 105. Since the larger of the two numbers is reduced, repeating this process gives successively smaller numbers, so this repetition will necessarily stop sooner or later — when the numbers are equal (if the process is attempted once more, one of the numbers will become 0).*/` ``` ``` ``` ``` `#include` `#include` `#include` ``` ``` `using namespace std;` `int gcd(int u, int v)` `{` ` return (v != 0) ? gcd(v, u % v) : u;` `}` ``` ``` `int main(void)` `{` ` int num1, num2, result;` ` cout << "Enter two numbers to find GCD using Euclidean algorithm: ";` ` cin >> num1 >> num2;` ` result = gcd(num1, num2);` ` if (gcd)` ` cout << "\nThe GCD of " << num1 << " and " << num2 << " is: " << result` ` << endl;` ` else` ` cout << "\nInvalid input!!!\n";` ` return 0;` `}` ``` ``` ```/* ``` `Enter two numbers to find GCD using Euclidean algorithm: 12 30` `The GCD of 12 and 30 is: 6`

#### 565 c++/11_Numerical_Problems/C++ Program to Find Inverse of a Matrix.cpp Unescape Escape View File

 `@ -1,565 +0,0 @@` `#if !defined(MATRIX_H)` `#define MATRIX_H` `#include ` `#include ` `#include ` `#include ` `#include ` `class CMatrix` `{` `private:` ` int m_rows;` ` int m_cols;` ` char m_name[128];` ` CMatrix();` `public:` ` double **m_pData;` ` CMatrix(const char *name, int rows, int cols) :` ` m_rows(rows), m_cols(cols)` ` {` ` strcpy(m_name, name);` ` m_pData = new double*[m_rows];` ` for (int i = 0; i < m_rows; i++)` ` m_pData[i] = new double[m_cols];` ` for (int i = 0; i < m_rows; i++)` ` {` ` for (int j = 0; j < m_cols; j++)` ` {` ` m_pData[i][j] = 0.0;` ` }` ` }` ` }` ` CMatrix(const CMatrix &other)` ` {` ` strcpy(m_name, other.m_name);` ` m_rows = other.m_rows;` ` m_cols = other.m_cols;` ` m_pData = new double*[m_rows];` ` for (int i = 0; i < m_rows; i++)` ` m_pData[i] = new double[m_cols];` ` for (int i = 0; i < m_rows; i++)` ` {` ` for (int j = 0; j < m_cols; j++)` ` {` ` m_pData[i][j] = other.m_pData[i][j];` ` }` ` }` ` }` ` ~CMatrix()`