CBSE 2008
Explain : If the two dimensional array contains
1 2 4
3 5 6
4 3 2
2 1 5
The output should appear as :
Product of Column 1 = 24
Product of Column 2 = 30
Product of Column 3 = 240
#include <iostream.h>
#include <conio.h>
#define r 10
# define c 10
void ProCol(int a[][], int m , int n)
// n represents column
// m represents row
{
int pro[n], i, j ;
for(i = 0; i < n ; i++)
{
pro[i] = 1;
for(j = 0 ; j < m ; j ++)
{
pro[i] = pro[i] * a[j][i];
}
cout << "\n Product of Column 1 : " << pro[i];
}
}
void main()
{
int arr[r][c];
int row, col, i, j;
// Input dimension ~
cout << "\n Enter row & Column :";
cin >> row >> col ;
// Input elements for the array ~
for( i = 0; i < row ; i++)
for ( j = 0 ; j < col ; j++)
{
cout << "\n Enter the element for position : " << i+1 << " , " << j+1 ;
cin >> arr[i][j];
}
// Display the array
for( i = 0; i < row ; i++ )
{
for( j =0 ; j < col ; j ++)
cout << arr[i][j] << " ";
cout << endl;
}
// Calling the function
ProCol(arr, row, col);
getch();
}
No comments:
Post a Comment