File Edit Options Buffers Tools C++ Help

#include <iostream>
#include <cmath>
using namespace std;

void printArray(const int a[], int size);
void reverse(const int a[], int aReverse[], int size);
int average(const int a[], int size);


int main()
{
  int size = 10;
  int a[] = {10, 15, 27, 89, 90, 95, 27, 13, 99, 33};
  int aReverse;

  cout << "The original array: ";
  printArray(a,10);
  cout << endl;

  reverse(a, aReverse, size);
  cout << "The reversed array is: ";
  printArray(aReverse,10);
  cout << endl;

  cout << "The average of the array is: "
       << average(a, 10) << endl;


  return 0;
}

void printArray(const int a[], int size)
{
  for (int i = 0; i < size; i++)
    cout << a[i] << " ";
}
void reverse(const int a[], int aReverse[], int size)
{
  for(int i = 0, j = size - 1; i < size; i++, j--)
    {
      aReverse[j] = a[i];
  }
}

int average(const int a[], int size)
{
  int sum = 0;
  for (int i = 0; i < size; i++)
    sum += a[i];
  return sum / size;
}

Recommended Answers

All 2 Replies

File Edit Options Buffers Tools C++ Help

void printArray(const int a[], int size);
void reverse(const int a[], int aReverse[], int size);
int average(const int a[], int size);


int main()
{
int size = 10;
int a[] = {10, 15, 27, 89, 90, 95, 27, 13, 99, 33};
int aReverse;

reverse(a, aReverse, size);
cout << "The reversed array is: ";
printArray(aReverse,10);
cout << endl;

void reverse(const int a[], int aReverse[], int size)
{
for(int i = 0, j = size - 1; i < size; i++, j--)
{
aReverse[j] = a;
}
}

You have defined aReverse as an integer, yet in your method signature it appears to be an array of integers. I suppose that would be it.

i think u want to do some thing like this,

#include <iostream>
#include <cmath>
using namespace std;

void printArray(int a[], int size);
void reverse(int a[], int size);
int average(int a[], int size);


int main()
{
	const int size = 10;
	int a[] = {10, 15, 27, 89, 90, 95, 27, 13, 99, 33};
	
	cout << "ay: ";
	printArray(a,10);
	cout << endl;
	
	reverse(a,size);
	cout << "The reversed array is: ";
	printArray(a,size);
	cout << endl;
	
	cout << "The average of the array is: "
		<< average(a, size) << endl;
	
	
	return 0;
}

void printArray(int a[], int size)
{
	for (int i = 0; i < size; i++)
		cout << a[i] << " ";
}
void reverse(int a[],int size)
{
	int temp=0;
	for(int i=0;i<=(size)/2;i++)
	{
		temp=a[i];
		a[i]=a[size-i-1];
		a[size-i-1]=temp;
	}
}

int average(int a[], int size)
{
	int sum = 0;
	for (int i = 0; i < size; i++)
		sum += a[i];

	return (sum / size);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.