Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // maxValplusCertainNum.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- int main()
- {
- int narray[3][3], choice, sChoice;
- std::cout << "Please input 9 numbers: " << std::endl;
- for (int i = 0; i < 3; i++)
- for (int j = 0; j < 3; j++)
- std::cin >> narray[i][j];
- std::cout << "Current array: " << std::endl;
- std::cout << "\tColumn 1:\tColumn 2:\tColumn 3:" << std::endl;
- for (int i = 0; i < 3; i++)
- {
- std::cout << "Row " << i+1 << ": \t";
- for (int j = 0; j < 3; j++)
- {
- std::cout << narray[i][j];
- std::cout << "\t\t";
- }
- std::cout << std::endl;
- }
- std::cout << "1. Max value 2. Certain Number Search" << std::endl;
- std::cout << "Please a number as input to your choice: ";
- std::cin >> choice;
- std::cout << std::endl;
- switch (choice)
- {
- case 1:
- {
- int max;
- std::cout << "Please input the number of the row you're searching in, or enter 4 for a diagonal search, or 0 for a search across all the array: ";
- std::cin >> sChoice;
- std::cout << std::endl;
- if (!sChoice)
- {
- max = narray[0][0];
- for (int i = 0; i < 3; i++)
- for (int j = 0; j < 3; j++)
- max < narray[i][j] ? max = narray[i][j] : 0;
- std::cout << "Maximum number across the array is " << max << "." << std::endl;
- break;
- }
- if (sChoice < 4 && sChoice > 0)
- {
- max = narray[sChoice-1][0]; //Row search, for Column search: max = narray[0][sChoice];
- for (int i = 0; i < 3; i++)
- max < narray[sChoice-1][i] ? max = narray[sChoice-1][i] : 0;
- std::cout << "Maximum number in row number " << sChoice << " is " << max << "." << std::endl;
- break;
- }
- if (sChoice == 4)
- {
- max = narray[0][0];
- for (int i = 1; i < 3; i++)
- max < narray[i][i] ? max = narray[i][i] : 0;
- std::cout << "The largest number across the left to right diagonal is " << max << "." << std::endl;
- }
- break;
- }
- case 2:
- {
- std::cout << "Please input the number you're searching for: ";
- std::cin >> sChoice;
- std::cout << std::endl;
- int row = -1, column;
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- if (sChoice == narray[i][j])
- {
- row = i;
- column = j;
- break;
- }
- }
- }
- if (row == -1)
- std::cout << "The number " << sChoice << " does not exist in the array." << std::endl;
- else
- std::cout << "The number " << sChoice << " exists in row number " << row+1 << " and column number " << column+1 << "." << std::endl;
- break;
- }
- default:
- {
- while (choice != 1 && choice != 2)
- {
- std::cout << "Please input 1 or 2 only: ";
- std::cin >> choice;
- std::cout << std::endl;
- }
- break;
- }
- }
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement