Pozdravljeni!

Zacenjam se uciti programiranja v C-ju in sem ze prisel do prvega problema, ki
ga ne znam resiti. V tekstu C v 21 dneh se pojavi tale naloga:
11. Write a recursive function to take the value 3 to the power of another 
number. For example, if 4 is passed, the function will return 81.               

Meni je na to temo uspelo spacati nekaj podobnega temu (c source pripet v
datoteki 3_potenca.c). Vendar sem ugotovil, da zdeva segfaultne pri 8 vrstici p
= potenca(x);

Mi lahko kdo pomaga, da bi mi tole potegnilo?

Vnaprej hvala!

Bostjan                                      
-- 
Boštjan Müller [NEONATUS], [EMAIL PROTECTED], http://neonatus.net/~neonatus
For my PGP key finger: [EMAIL PROTECTED], RSA id: 0x90178DBD, ICQ #:7506644
    Celular: +386(0)41243189, Powered by Debian GNU/LiNUX , Student of VFUL
                  Weird enough for government work.
#include <stdio.h>
unsigned int p, x;
unsigned int potenca(unsigned int a);
main ()
{
	printf("Enter the number to put the power on 3\n");
	scanf("%d", &x);
//	p = potenca(x);
	printf("3^%u is %u\n", x, p);
	return 0;
}
unsigned int potenca(unsigned int a)
{
	if (a == 1)
		return 3;
	else
	{
		a *= potenca(a);
		return a;
	}
}

Reply via email to