Code:
// F-ja za dizanje broja a, na n-ti stepen
# include <iostream>
using namespace std;
long step(int x, unsigned short n); // prototip f-je step
int main()
{
short a;
unsigned short n;
long rezult;
cout << endl << " Program podize broj `a` na n-ti stepen";
cout << endl << endl << " Unesite a: ";
cin >> a;
cout << endl << " Unesite n: ";
cin >> n;
rezult = step(a, n);
cout << endl << "Rezultat je: " << rezult;
return 0;
}
long step(short v, unsigned short w)
{
if (w<0) {
cout << "\n" << "Ne znam da radim sa negativnim stepenima.";
return 0;
}
if (w==0)
return (1);
if (w==1)
return (v);
return (v * step(v, w-1));
}
Code:
cd /home/filip/
g++ -o step -Wall step.cc
step.cc: In function `long int step(short int, short unsigned int)':
step.cc:31: warning: comparison is always false due to limited range of data
type
Compilation finished at Mon Aug 4 22:54:14
f