Hi, I have a program that executes, but it is not recursive. I would appreciate any help on this. Thanks in advance. (Thanks to DavesTips for his previous help on this program). The program is supposed to implement the factorial function recursively. You can execute it to see the output. n! needs a value as well. Here it is:
Thanks again for any responses...
Code:
#include <iostream>
#include <iomanip>
using namespace std; //Standard namespace is being used
void FindBlock(int aBmp[][5], int nSize, int cx, int cy){ //An array
//is being initialized in order to create the picture
if ((aBmp[cx][cy] == 0) || aBmp[cx][cy] > 1) return;
if (aBmp[cx][cy] == 1) aBmp[cx][cy] = 2;
if (cx > 0) FindBlock(aBmp, nSize, cx - 1, cy);
if (cx < nSize-1) FindBlock(aBmp, nSize, cx+1, cy);
if (cy > 0) FindBlock(aBmp, nSize, cy, cy - 1);
if (cy < nSize-1) FindBlock(aBmp, nSize, cx, cy+1);
}
void ClearBlock(int aBmp[][5], int nSize) //The objects that
//have been visited in the picture will be cleared
{
for (int m=0; m < nSize; m++)
for (int n=0; n < nSize; n++)
if (aBmp[m][n] > 1) aBmp[m][n] = 0;
}
void ErasePic(int aBmp[][5], int nSize, int cx, int cy)
//The object will be erased which the given black pixel is part
{
FindBlock(aBmp, nSize, cx, cy);
ClearBlock(aBmp, nSize);
}
void printBlock(int aBmp[][5], int nSize)
//Original picture will be printed first, then new picture
//will be printed
{
for (int m=0; m < nSize; m++)
{
for (int n=0; n < nSize; n++)
cout << setw(3) << aBmp[m][n];
cout << endl;
}
cout <<" *************" << endl;; //Asterisk is used
//to separate original picture from new picture
}
int main(int argc, char* argv[])
{
cout << "Program Assignment 2: ErasePic Funtion\n" << endl;
//Title of project
cout <<" Initial Image" << endl; //Initial picture will apear underneath
cout <<" *************" << endl;
int block[5][5] = //Prints picture in a 5x5 block
{{1,1,0,1,0},
{1,0,0,1,1},
{1,0,1,1,1},
{1,0,1,1,0},
{0,0,1,0,0}};
printBlock(block,5);
ErasePic(block,5,2,2);
printBlock(block,5);
cout <<" After Execution\n\n" << endl; //New picture will appear underneath
return 0;
}
Thanks again for any responses...