#include <iostream>
int largestNumber(int nVariables, int numbers[]) //pass number of variables and number array
{
int largest = numbers[0]; //initiate largest as the number at index 0
for (int i = 0; i <= nVariables; i++) { //for loop to iterate through the numbers array that is nVariables long
largest = (largest<numbers[i]?numbers[i]:largest);
//^ternary operator same as:
/*
if(largest < numbers[i]){
largest = numbers[i]; //sets largest as numbers[current iteration of i]
}
else{
largest = largest; // stays same
}
*/
}
return largest;
}
int main()
{
int nOfVariables;
std::cout << "Input number of variables: ";
std::cin >> nOfVariables;
int variables[nOfVariables - 1];
for (int i = 0; i < nOfVariables; i++) {
std::cout << "Enter Variable #" << i + 1 << ": ";
std::cin >> variables[i];
}
std::cout << std::endl;
std::cout << std::endl << largestNumber(nOfVariables, variables) << std::endl;
}
#include<iostream>
using namespace std;
void ro(int matrix1[][4]);
int main()
{
int matrix1[6][4] = { //Always First Periorty Row & Second Periorty Colums
{42, 32, 42, 52 }, //Initilize 2D Array 6 Rows & 4 Colums
{43, 34, 23, 53 },
{23, 54, 24, 3 },
{3, 5, 6, 55 },
{34, 6, 45, 56 },
{45, 56, 56, 57 }
};
ro(matrix1);
return 0;
}
void ro(int matrix1[][4])
{
for (int MainRowIndex = 0; MainRowIndex < 6; MainRowIndex++) // Main loop which decided which number of row check
{
int ColumnIndex = 0, MainRowIndexTeller = 0, ColoumsIndexTeller = 0; // Decalaration && Inilization for Find Row & Colum Index in Every Main Row
for (ColumnIndex = 0; ColumnIndex < 4; ColumnIndex++)
{
int max = matrix1[MainRowIndex][0]; //Here We assign Every First element of row equal to Maximum Number
if (matrix1[MainRowIndex][ColumnIndex] > max)
{
matrix1[MainRowIndex][0] = matrix1[MainRowIndex][ColumnIndex]; //Here Condition When first row Main Element is Less than Any other Element of this Specific row Than We assign the Maximum Element to first row Main Element.
MainRowIndexTeller = MainRowIndex; ColoumsIndexTeller = ColumnIndex; //Here We Note the Running Index
}
}
if (MainRowIndex == 0)
{
cout << "In Ist Row:: Maximum Value is " << matrix1[MainRowIndex][0] << " Which Row&Colum No " << (1 + MainRowIndexTeller) << (1 + ColoumsIndexTeller) << "
";
}
if (MainRowIndex == 1)
{
cout << "In 2nd Row:: Maximum Value is " << matrix1[MainRowIndex][0] << " Which Row&Colum No " << (1 + MainRowIndexTeller) << (1 + ColoumsIndexTeller) << "
";
}
else if (MainRowIndex == 2)
{
cout << "In 3rd Row:: Maximum Value is " << matrix1[MainRowIndex][0] << " Which Row&Colum No " << (1 + MainRowIndexTeller) << (1 + ColoumsIndexTeller) << "
";
}
else if (MainRowIndex > 2)
{
cout << "In " << (1 + MainRowIndex) << "th Row:: Maximum Value is " << matrix1[MainRowIndex][0] << " Which Row & Colum No " << (1 + MainRowIndexTeller) << (1 + ColoumsIndexTeller) << "
";
}
}
}