0% found this document useful (0 votes)
38 views3 pages

My

This C++ program defines multiple functions that perform operations on arrays: 1. The sum() function adds two input arrays element-wise and stores the results in a third array. 2. The chec() function checks if any elements are common between two input arrays and prints the positions if a match is found. 3. The trans() function transposes a 2D input array and stores the results in a second array. 4. Additional functions perform operations like rotating a 2D array, multiplying diagonals of a 2D array, checking for a matching value, and calculating the average of a 3D array.

Uploaded by

Muhammad Bilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

My

This C++ program defines multiple functions that perform operations on arrays: 1. The sum() function adds two input arrays element-wise and stores the results in a third array. 2. The chec() function checks if any elements are common between two input arrays and prints the positions if a match is found. 3. The trans() function transposes a 2D input array and stores the results in a second array. 4. Additional functions perform operations like rotating a 2D array, multiplying diagonals of a 2D array, checking for a matching value, and calculating the average of a 3D array.

Uploaded by

Muhammad Bilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream> //Muhammad Bilal Ali Saif

#include"23i-2004_A_.h" //23i-2004

int sum(int array1[], int array2[], int array3[])


{
for (int i = 0; i < 5; i++)
{
cout << "Enter the value of element(" << i << ") : ";
cin >> array1[i];
array3[i] = array1[i] + array2[i];
}
for (int i = 0; i < 5; i++)
{
cout << i << " element of 3rd array is : " << array3[i] << endl;
}
return 0;
}
int chec(int arr4[], int arr5[])
{
bool check = 0;
for (int i = 0; i < 7; i++)
{
for (int a = 0; a < 7; a++)
{
if (arr4[a] == arr5[i])
{
cout << "There is a common element at position(" << a << ") of
array1 and at position(" << i << ")" << endl;
check = 1;
}
}
if (check != 1)
cout << "No two elements are equal in both arrays." << endl;
}
return 0;
}
int trans(int arr6[3][3], int arr7[3][3])
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
arr7[i][j] = arr6[j][i];
}
}
cout << "Transpose of Matrix :\n";
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
cout << arr7[i][j] << "\t";
cout << endl;
}
return 0;
}
int turn(int arr8[4][6], int arr9[6][4]){
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 6; j++)
{
arr9[j][3 - i] = arr8[i][j];
}
}
cout << "\nRotated array by 90 degrees :\n";
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 4; j++)
{
cout << arr9[i][j] << " ";
}
cout << endl;
}
return 0;
}
int multiply(int arr10[5][5]){
int prod1 = 1, prod2 = 1;
for (int i = 0, j = 0; i < 5, j < 5; i++, j++)
{

prod1 = prod1 * arr10[i][j];


}
cout << "The result of product of elements present at diognal starting from
left is : " << prod1 << endl;

for (int i = 0, j = 4; i < 5, j >= 0; i++, j--)


{

prod2 = prod2 * arr10[i][j];


}
cout << "The result of product of elements present at diognal starting from
right is : " << prod2 << endl;
return 0;
}
int equal(int arr11[4][4]){
int us;
cout << "Enter a value : ";
cin >> us;

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


{
for (int j = 0; j < 4; j++)
{
if (us == arr11[i][j])
{
cout << "Entered values of user matches at position (" << i + 1 <<
") (" << j + 1 << ") of the matrix";
}
}
}
return 0;
}
double avg(int arr12[4][4][4]){
int avg = 0;
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 3; j++)
{
for (int k = 0; k <= 3; k++)
{
avg += arr12[i][j][k];
}
}
}
cout << "\nNow the average is :" << avg / (4 * 4 * 4) << endl;
return 0;
}

You might also like