Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int i, j, arraySize;
- void fillArray(double **);
- void showArray(double **);
- void showInvDiag(double **);
- void showOtherDiags(double **);
- /* Trouble arises when calling 'showInvDiag'
- void displayEverything(double **array){
- showArray(array);
- showInvDiag(array);
- showOtherDiags(array);
- }
- */
- int main(){
- cout << "Number of lines and columns: "; cin >> arraySize;
- // Create the 2D array
- //****************************************************************
- double **array;
- array = new double *[arraySize];
- for(i = 0; i < arraySize; i++) array[i] = new double [arraySize];
- //****************************************************************
- fillArray(array);
- //displayEverything(array); // Not working fully
- showArray(array);
- showInvDiag(array);
- showOtherDiags(array);
- return 0;
- }
- void fillArray(double **array){
- for(i = 0; i < arraySize; i++){
- for(j = 0; j < arraySize; j++){
- cout << "(" << i << ", "<< j << ") = ";
- cin >> array[i][j];
- }
- }
- cout << endl;
- }
- void showArray(double **array){
- for(i = 0; i < arraySize; i++){
- for(j = 0; j < arraySize; j++) cout << array[i][j] << " ";
- cout << endl;
- }
- cout << endl;
- }
- void showInvDiag(double **array){
- double *diagSum;
- *diagSum = 0;
- j = arraySize - 1;
- cout <<"\nInverse Diagonal values are: " << endl;
- for(i = 0; i < arraySize; i++){
- *diagSum += array[i][j];
- cout << array[i][j--] << " ";
- }
- cout << "\n\nInverse diagonal arithmetic average: " << *diagSum / arraySize << endl;
- delete diagSum;
- }
- void showOtherDiags(double **array){
- int holdX = 0, holdY = 0;
- int x, y;
- j = 1;
- cout << "\nOther inverse diagonals." << endl;
- cout << "*************************************" << endl;
- // Upper-Left Diagonal Triangle
- while(j <= arraySize - 1){
- x = holdX; y = holdY;
- for(i = 0; i < j; i++) cout << array[x++][y--] << " ";
- cout << endl;
- holdY++; j++;
- }
- // Lower-Right Diagonal Triangle
- j = arraySize - 1, holdX = 1, holdY = arraySize - 1;
- while(j >= 1){
- x = holdX; y = holdY;
- for(i = 0; i < j; i++) cout << array[x++][y--] << " ";
- cout << endl;
- holdX++; j--;
- }
- cout << "*************************************" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment