Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

find largest number in each row in array c++ using function

#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) << "

";
		}
	}
}
 
PREVIOUS NEXT
Tagged: #find #largest #number #row #array #function
ADD COMMENT
Topic
Name
3+5 =