diff --git a/Others/Buzz_number.cpp b/others/Buzz_number.cpp similarity index 100% rename from Others/Buzz_number.cpp rename to others/Buzz_number.cpp diff --git a/Others/Decimal To Binary.cpp b/others/Decimal To Binary.cpp similarity index 100% rename from Others/Decimal To Binary.cpp rename to others/Decimal To Binary.cpp diff --git a/Others/Decimal To Hexadecimal .cpp b/others/Decimal To Hexadecimal .cpp similarity index 100% rename from Others/Decimal To Hexadecimal .cpp rename to others/Decimal To Hexadecimal .cpp diff --git a/Others/Decimal to Roman Numeral.cpp b/others/Decimal to Roman Numeral.cpp similarity index 100% rename from Others/Decimal to Roman Numeral.cpp rename to others/Decimal to Roman Numeral.cpp diff --git a/Others/GCD_of_n_numbers.cpp b/others/GCD_of_n_numbers.cpp similarity index 100% rename from Others/GCD_of_n_numbers.cpp rename to others/GCD_of_n_numbers.cpp diff --git a/Others/Palindromeofnumber.cpp b/others/Palindromeofnumber.cpp similarity index 100% rename from Others/Palindromeofnumber.cpp rename to others/Palindromeofnumber.cpp diff --git a/Others/Paranthesis Matching.cpp b/others/Paranthesis Matching.cpp similarity index 100% rename from Others/Paranthesis Matching.cpp rename to others/Paranthesis Matching.cpp diff --git a/Others/Primality Test.cpp b/others/Primality Test.cpp similarity index 100% rename from Others/Primality Test.cpp rename to others/Primality Test.cpp diff --git a/Others/Sparse matrix.cpp b/others/Sparse matrix.cpp similarity index 100% rename from Others/Sparse matrix.cpp rename to others/Sparse matrix.cpp diff --git a/Others/Strassen Matrix Multiplication.cpp b/others/Strassen Matrix Multiplication.cpp similarity index 100% rename from Others/Strassen Matrix Multiplication.cpp rename to others/Strassen Matrix Multiplication.cpp diff --git a/Others/String Fibonacci.cpp b/others/String Fibonacci.cpp similarity index 100% rename from Others/String Fibonacci.cpp rename to others/String Fibonacci.cpp diff --git a/Others/Tower of Hanoi.cpp b/others/Tower of Hanoi.cpp similarity index 100% rename from Others/Tower of Hanoi.cpp rename to others/Tower of Hanoi.cpp diff --git a/Others/fibonacci.cpp b/others/fibonacci.cpp similarity index 100% rename from Others/fibonacci.cpp rename to others/fibonacci.cpp diff --git a/Others/happy_number.cpp b/others/happy_number.cpp similarity index 100% rename from Others/happy_number.cpp rename to others/happy_number.cpp diff --git a/Others/pascal_triangle.cpp b/others/pascal_triangle.cpp similarity index 94% rename from Others/pascal_triangle.cpp rename to others/pascal_triangle.cpp index b6f762d97..101100018 100644 --- a/Others/pascal_triangle.cpp +++ b/others/pascal_triangle.cpp @@ -1,63 +1,63 @@ -#include - -using namespace std; - -void show_pascal(int **arr, int n) -{ - //pint Pascal's Triangle - for (int i = 0; i < n; ++i) - { - for (int j = 0; j < n + i; ++j) - { - if (arr[i][j] == 0) - cout << " "; - else - cout << arr[i][j]; - } - cout << endl; - } -} - -int **pascal_triangle(int **arr, int n) -{ - for (int i = 0; i < n; ++i) - { - for (int j = n - i - 1; j < n + i; ++j) - { - if (j == n - i - 1 || j == n + i - 1) - arr[i][j] = 1; //The edge of the Pascal triangle goes in 1 - else - arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j + 1]; - } - } - - return arr; -} - -int main() -{ - int n = 0; - - cout << "Set Pascal's Triangle Height" << endl; - cin >> n; - - //memory allocation (Assign two-dimensional array to store Pascal triangle) - int **arr = new int*[n]; - for (int i = 0; i < n; ++i) - { - arr[i] = new int[2 * n - 1]; - memset(arr[i], 0, sizeof(int)*(2 * n - 1)); - } - - pascal_triangle(arr, n); - show_pascal(arr, n); - - //deallocation - for (int i = 0; i < n; ++i) - { - delete[] arr[i]; - } - delete[] arr; - - return 0; -} +#include + +using namespace std; + +void show_pascal(int **arr, int n) +{ + //pint Pascal's Triangle + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < n + i; ++j) + { + if (arr[i][j] == 0) + cout << " "; + else + cout << arr[i][j]; + } + cout << endl; + } +} + +int **pascal_triangle(int **arr, int n) +{ + for (int i = 0; i < n; ++i) + { + for (int j = n - i - 1; j < n + i; ++j) + { + if (j == n - i - 1 || j == n + i - 1) + arr[i][j] = 1; //The edge of the Pascal triangle goes in 1 + else + arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j + 1]; + } + } + + return arr; +} + +int main() +{ + int n = 0; + + cout << "Set Pascal's Triangle Height" << endl; + cin >> n; + + //memory allocation (Assign two-dimensional array to store Pascal triangle) + int **arr = new int*[n]; + for (int i = 0; i < n; ++i) + { + arr[i] = new int[2 * n - 1]; + memset(arr[i], 0, sizeof(int)*(2 * n - 1)); + } + + pascal_triangle(arr, n); + show_pascal(arr, n); + + //deallocation + for (int i = 0; i < n; ++i) + { + delete[] arr[i]; + } + delete[] arr; + + return 0; +} diff --git a/Others/sieve_of_Eratosthenes.cpp b/others/sieve_of_Eratosthenes.cpp similarity index 100% rename from Others/sieve_of_Eratosthenes.cpp rename to others/sieve_of_Eratosthenes.cpp diff --git a/Others/smallest-circle.cpp b/others/smallest-circle.cpp similarity index 100% rename from Others/smallest-circle.cpp rename to others/smallest-circle.cpp diff --git a/Others/spiral_print.cpp b/others/spiral_print.cpp similarity index 94% rename from Others/spiral_print.cpp rename to others/spiral_print.cpp index 1a843c8cd..e6e6899ef 100644 --- a/Others/spiral_print.cpp +++ b/others/spiral_print.cpp @@ -1,78 +1,78 @@ -#include -using namespace std; - -void genArray(int a[][10], int r, int c) -{ - - int value = 1; - for (int i = 0; i < r; i++) - { - for (int j = 0; j < c; j++) - { - a[i][j] = value; - cout << a[i][j] << " "; - value++; - } - cout << endl; - } -} -void spiralPrint(int a[][10], int r, int c) -{ - - int startRow = 0, endRow = r - 1; - int startCol = 0, endCol = c - 1; - int cnt = 0; - - while (startRow <= endRow && startCol <= endCol) - { - - ///Print start row - for (int i = startCol; i <= endCol; i++, cnt++) - { - cout << a[startRow][i] << " "; - } - startRow++; - - ///Print the end col - for (int i = startRow; i <= endRow; i++, cnt++) - { - cout << a[i][endCol] << " "; - } - endCol--; - - ///Print the end row - if (cnt == r * c) - { - break; - } - - for (int i = endCol; i >= startCol; i--, cnt++) - { - cout << a[endRow][i] << " "; - } - endRow--; - - ///Print the start Col - if (cnt == r * c) - { - break; - } - for (int i = endRow; i >= startRow; i--, cnt++) - { - cout << a[i][startCol] << " "; - } - startCol++; - } -} - -int main() -{ - int a[10][10]; - - int r, c; - cin >> r >> c; - genArray(a, r, c); - spiralPrint(a, r, c); - - return 0; -} +#include +using namespace std; + +void genArray(int a[][10], int r, int c) +{ + + int value = 1; + for (int i = 0; i < r; i++) + { + for (int j = 0; j < c; j++) + { + a[i][j] = value; + cout << a[i][j] << " "; + value++; + } + cout << endl; + } +} +void spiralPrint(int a[][10], int r, int c) +{ + + int startRow = 0, endRow = r - 1; + int startCol = 0, endCol = c - 1; + int cnt = 0; + + while (startRow <= endRow && startCol <= endCol) + { + + ///Print start row + for (int i = startCol; i <= endCol; i++, cnt++) + { + cout << a[startRow][i] << " "; + } + startRow++; + + ///Print the end col + for (int i = startRow; i <= endRow; i++, cnt++) + { + cout << a[i][endCol] << " "; + } + endCol--; + + ///Print the end row + if (cnt == r * c) + { + break; + } + + for (int i = endCol; i >= startCol; i--, cnt++) + { + cout << a[endRow][i] << " "; + } + endRow--; + + ///Print the start Col + if (cnt == r * c) + { + break; + } + for (int i = endRow; i >= startRow; i--, cnt++) + { + cout << a[i][startCol] << " "; + } + startCol++; + } +} + +int main() +{ + int a[10][10]; + + int r, c; + cin >> r >> c; + genArray(a, r, c); + spiralPrint(a, r, c); + + return 0; +} diff --git a/Others/vector_important_functions.cpp b/others/vector_important_functions.cpp similarity index 100% rename from Others/vector_important_functions.cpp rename to others/vector_important_functions.cpp