Write a C++ program having a recursive function recursiveMinimum that takes an integer array and the array size as arguments and returns the smallest element of the array. The function should stop processing and return when it receives an array of 1 element.

#include <iostream>


int recursiveMinimum(int[], int);
int smallest, index;


int main()
{
int x=10;
int array1[10];
smallest=0;
index=0;


return 0;
}



int recursiveMinimum(int array[], int size)
{
if (size<=1) return -1;
if array[index]<smallest
smallest=array[index];
index++;
recursiveMinimum(array, size);
return smallest;
}

this is error i getompiling...

program8.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\project8\program8.cpp(15) : warning C4101: 'array1' : unreferenced local variable
C:\Program Files\Microsoft Visual Studio\MyProjects\project8\program8.cpp(26) : error C2061: syntax error : identifier 'array'
Error executing cl.exe.


project8.exe - 1 error(s), 1 warning(s)

Those are exceptionally detailed and clear diagnostic messages. What's the problem? 'array1' isn't used and 'array' isn't expected where you put it. Both fixes require no more than a remedial knowledge of C++.

candykane, the first is a warning, which means your code is not technically incorrect there. But you have a variable named 'array1', which you aren't using for anything at all! The compiler, being nice and friendly (in a sarcastic sort of way) is telling you this, since maybe it means you made an error, or just have code that could use some cleaning.

The second error is a syntax error (as the compiler informs you). 'if' branches do not use that sort of syntax in C++.

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.