You are on page 1of 3

MudassarAbdullah Lab Report 1

L1f19bsee0029

Q1: Write a program which will take ten values from the user. And the program should display
the average of those ten values. This problem should be done through pointers.

#include<iostream>
using namespace std;
int main()
{
int avg, number[10],sum ;
int *ptr;
cout << "Please enter any 10 number to find the average ........." << endl;
for (int i=0;i<10;i++){
cout << i+1 << ":";
cin>>number[i];
ptr=&number[i];
sum += *ptr;
}
avg = sum /10;
cout << "The average of 10 number is :" << avg << endl;
}
MudassarAbdullah Lab Report 1
L1f19bsee0029

Q2: Input and Display the 3 x 3 matrix through 2D pointer. Write a function which will find
out and then display the maximum and minimum values in matrix.

#include <iostream>
using namespace std;
int main()
{ //l1f19bsee0029
int a[3][3],i,j,high,small;
int (*pnt)[3];// declwaring 2d pointers
pnt=a;
cout<<"enter the values of matrix"<<endl;
for(int i=0;i<3;i++)
{ // nested for loop for enteries mean cin>>
for(int j=0;j<3;j++)
{
cin>>*(*(pnt+i)+j);
}
}
cout<<"yor entered matrix is "<<endl;
for(int i=0;i<3;i++) // for loop to display valuses
{
for(int j=0;j<3;j++)
{
cout<<a[i][j]<<endl;
}
}
high = a[0][0];
small = a[0][0];
// program to find the maximum and minumum
for (i = 1; i<3; i++)
{
for (j = 1; j<3; j++)
{
if (a[i][j] > high)
{
high = a[i][j];
}

if (a[i][j] < small)


{
small = a[i][j];
}
}

}
MudassarAbdullah Lab Report 1
L1f19bsee0029

cout << endl<<" Maximum element of matrix is =" << high << endl;
cout << "Minimum element of matrixis =" << small;

You might also like