You are on page 1of 2

ABDULLAH KHAN RAJA

BCS231095
Walkthrough task:
Write a C++ program that creates (in main function) an array of type float having 10 elements (for 10
students). After that, pass that array to the function named “inputValues” which takes input in that
array. For passing array, you should use reference pointers. After that, create another function named
“findAverage” and pass that array (using reference pointer) to that function. The “findAverage”
function should calculate the average of the marks of the 10students and update or report the average
using a reference variable (Note: Do not use return) to the main function.

CODE :
#include<iostream>
using namespace std;
void inputArray(int ptr[], int size) {
cout << "enter 10 values for array" << endl;
for (int i = 0; i < size; i++)
{
cin >> ptr[i];
}
}

void findAverage(int ptr[], int size, int& avg) {


int sum = 0;
for (int i = 0; i < size; i++)

sum = sum + ptr[i];

avg = sum / size;


}

void main() {
int arr[10];
int size = 10;
int average = 0;
inputArray(arr, size);
findAverage(arr, 10, average);
cout << "Average marks:" << average << endl;

Output:

You might also like