You are on page 1of 2

Activity 1(Array)

#include<iostream>
using namespace std;

int main()
{
int m,n;
int a[size][size] ERROR;
cout<<”enter the number of rows”<<endl;
cin>>m;
cout<<”enter the number of columns”<<endl;
cin>>n;

cout<<”enter the elements in table”<<endl;


for(int i = 0; i<m; i++)
{
for(int j = 0; j<n; j++)
{
cin>>a[i][j];
}
}
//output each array element’s value
for(int i = 0; i<m; i++)
for(int j = 0; j<n; j++)
{
cout<<”a[“<<i<<”][“<<j<<”]”;
cout>>a[i][j]<<endl;
}
return 0;
}

CORRECT CODES: OUTPUT:


Activity 2 (Array)

#include<iostream>
using namespace std;  ERROR
const int max  ERROR = 5;

int main()
{
int arr[MAX ERROR] = {10,20,30,40,50}
int *ptr[MAX ERROR];

for(int i = 0; i<MAX ERROR; i++)


{
ptr[i] = &arr[i]; //assign the address of integer
}
for(int i=0; i<MAX ERROR; i++)
{
cout<<”value of var[“<<i<<”] = “<<*ptr[i]<<endl;
}
return 0;
}

CORRECT CODES

OUTPUT:

You might also like