evo code 1: samo mi se ugasi kad pokrene funkciju stk() zasto?????
#include <iostream>
#include <math.h>
using namespace std;
unsigned x = 0;
int show = 1;
const int size = 100000;
const int calls = 20;
void stk()
{
int a[size];
x++;
if(show)
cout << x << " " << flush;
stk();
}
int main()
{
cout << "Je Call: " << size << " * "
<< sizeof(int) << " Byte = " << size * sizeof(int) << " Byte " << endl;
cout << "ca " << calls << " calls, stacksize ca "
<< (calls * size * sizeof(int)) / 1000000 << " MB" << endl;
cout << endl << "show count? ";
cin >> show;
stk();
return 0;
}
a ovaj code mi se zakuca kad dodje da uradi power () zasto????
#include <iostream>
#include <math.h>
using namespace std;
int mult(int m, int n)
{
if(n == 0 || m == 0)
return 0;
if(n<0) {
n=-n;
m=-m;
}
return m + mult(m, n - 1);
//n = -n;
//return -mult(m, n);
}
int power(int m, unsigned int n)
{
if(m == 0)
return 0;
if(n == 0)
return 1;
return mult(m, power(m, n - 1));
}
int main()
{
int z;
int m, n;
do {
cout << "m,n: ";
cin >> m >> n;
cout << "Mult: " << mult(m, n) << endl;
if(n >= 0)
cout << "Power: " << power(m, n) << endl;
cout << endl;
cout << "Nochmals? (0=Abbruch) ";
cin >> z;
} while(z != 0);
return 0;
}