• Register
143 points
‚óŹ3

This program takes n number of elements from user (where, n is specified by user) and stores data in an array. Then, this program displays the largest element of that array using loops.

To understand this example, you should have the knowledge of the following C++ programming topics:

·        C++ Arrays

·        C++ for Loop

·        C++ if, if...else and Nested if...else

 

This program takes n number of elements from user (where, n is specified by user) and stores data in an array. Then, this program displays the largest element of that array using loops.

This program takes n number of elements from user and stores it in array.

To find the largest element, the first two elements of array are checked and largest of these two element is placed in arr[0].

Then, the first and third elements are checked and largest of these two element is placed in arr[0].

This process continues until and first and last elements are checked.

After this process, the largest element of an array will be in arr[0] position.

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

int row,col;

cout<<"Enter no. of coloumns: ";

cin>>col;

cout<<"Enter no. of rows: ";

cin>>row;

int **MATRIX= new int *[row];

 

for (int i=0 ; i<col ; i++)

{

    MATRIX[i]= new int[col];

}

 

for (int i=0 ; i<col ; i++)

{

    for (int j=0 ; j<row ; j++)

    {

    cout<<"Enter an Element"<<i<<","<<j<<": ";

    cin>>MATRIX[i][j];

    }

}

double ANS=0;

for (int i=0 ; i<col ; i++)

{

    for (int j=0 ; j<row ; j++)

    {

    ANS+=pow(MATRIX[i][j],2);

    }

}

ANS=pow(ANS,0.5);

cout<<"Euclidean Norm is: "<<ANS<<endl;

delete[] MATRIX;

return 0;

}