Professional Documents
Culture Documents
b[0]=a[0];
b[1]=a[1];
b[2]=a[2];
b[3]=a[3];
………
………
b [ 10 ] = a [ 10 ] ;
}
Task
Input
Row 1 1 2 3
Row 2 Memory
4 5 6
Row 3 7 8 9 Row 3 7 8 9
Row 2 4 5 6
Row 1 1 2 3
a [rowIndex ] [ columnIndex ]
maxRows = 3;
maxCols = 3;
}
Task 2
int main() {
int arr[size];
int i, size, count = 0;
/* Input array elements */
cout<<"Enter elements in array : “<<endl;
for(i=0; i<size; i++)
{
cin>>arr[i];
cout<<endl;
}
/* Count total negative elements in array */
for(i=0; i<size; i++)
{
/* Increment count if current array element is negative */
if(arr[i] < 0)
{
count++;
}
}
Prepared by Aqsa Gul, Lecturer Institute of Management Sciences Peshawar
cout<<Total negative elements in array =“<< count;
return 0;
Task 3
Int main(){
Cout<<“Enter number of rows”<<endl;
Cin>>maxRows;
Cout<<“Enter number of columns”<<endl;
Cin>>maxCols;
int array[ maxRows ][ maxCols ] ; // 2-D array
//inserting values in array
for ( int row = 0 ; row < maxRows ; row ++ )
{
for (int col = 0 ; col < maxCols ; col ++ )
{
cout<<"Please enter value element number "<<row<< "," << col<<"\t";
cin >> a [ row ] [ col ] ;
}
}
//printing values from array
for(int i= 0; i<maxRow; i++)
{
for(int j=0; j<max Cols; j++)
{
cout<<a[i][j]<<“\t”;
Prepared by Aqsa Gul, Lecturer Institute of Management Sciences Peshawar
}
}