I'm not sure why, but this code compiles fine and runs until it reaches my function call (array_change). After debugging I noticed if I comment it out, the rest of the code runs. Why is this function call not able to initiate? Can anyone pls help?
Code:
Header File: recursion.h
#ifndef RECURSION_H
#define RECURSION_H
#include <iostream>
#include <string>
using namespace std;
const int SIZE = 10;
int array[SIZE][SIZE];
void array_change(int row, int col)
{
if(row > 9)
return;
if(col > 9)
row++;
while(col > 0 && row < 9)
{
array[row][col] = array[row-1][col] + array[row-1][col-1];
array_change(row,col+1);
}
}
#endif
Main File: main.cpp
#include "recursion.h"
int main ()
{
void array_change(int row, int col); // function prototype
for(int i=0 ; i < SIZE ; i++)
{
for(int j=0 ; j < SIZE ; j++)
{
array[i][j] = 1;
cout << " " << array[i][j];
}
cout << endl;
}
cout << "recursion!";
int row=1,col=1;
array_change(row,col);
for(int i=0 ; i < SIZE ; i++)
{
for(int j=0 ; j < SIZE ; j++)
{
cout << " " << array[i][j];
}
cout << endl;
}
cout << "the end!";
return 0;
}