1.

द्विविमीय ऐरे को उदाहरण सहित समझाइए।

Answer»

द्विविमीय ऐरे में, डाटा सारणी के रूप में संग्रहीत किया जाता है, जिसमें पंक्तियों (RowB) तथा स्तम्भों (Columns) का संयोजन (Combination) होता है। द्विविमीय ऐरे को मैट्रिक्स (Matrix) के नाम से भी जाना जाता है।

द्विविमीय ऐरे को घोषित करना

प्रारूप: data_type array_name [rows] {columns ] ;

उदाहरण int x [3] [4] ;
float matrix [20] [25];
पहली स्टेटमेण्ट में से 3 व कॉलम 4 है, इसलिए ऐरे का साइज (3 x 4 =) 12 होगा।

द्विविमीय ऐरे को प्रारम्भिक मान देना

एकविमीय ऐरे की तरह द्विविमीय ऐरे में भी उसका प्रारम्भिक मान रखना आवश्यक होता है, इसलिए ऐरे को कम्पाइल करते समय ही उसका प्रारम्भिक मान दे सकते हैं।
प्रारूप data_type array_name (rows] [columns] ={value1, value2, …, valueN);

अथवा

data_type array_name[rows] [columns] ={{value of 1st row}, {value of 2nd row},….};

उदाहरण

int x [3] [4] = (1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12}},
अथवा
int x [3][4] = ( 1, 2, 3, 4), (5, 6, 7, 8}, (9, 10, 11, 12} };

उदाहरण

मैट्रिक्स को प्रिण्ट करना
#include<iostream.h>
void main ( )
{
int m, n, A[10] [10],i,j;
cout<<“Enter the number of rows: “; cin>>m;
cout<<“Enter the number of columns : “; cin>>n;
cout<<“Enter the elements of the matrix” <<end1;
for(i=0;i<m; i++)
{
for(j=0; j<n; j++) { cin>>A[i][j];
}
}
cout<<“Matrix”<<end1;
for (i=0; i<m;i++)
{
for(j=0; j<n; j++)
{
cout<<A[i][j]<<” “;
}
cout<<end1;
}
}

आउटपुट

Enter the number of rows : 3
Enter the number of columns :3
Enter the elements of the matrix
5
6
7
8
9
5
6
4
3
Matrix
5 6 7
8 9 5
6 4 3



Discussion

No Comment Found

Related InterviewSolutions