Exemple #1
0
int main (void)
{
  long int x_to_the_n (int x, int n);

  printf("2 to the power of 2: %li\n", x_to_the_n (2, 2));
  printf("4 to the power of 4: %li\n", x_to_the_n (4, 4));
}
Exemple #2
0
int main(void) {
    int x, n;
    printf("Enter your numbers (x, n): ");
    scanf("%i, %i", &x, &n);
    printf("%i to the %i is: %li\n", x, n, x_to_the_n(x, n));

    return 0;
}
int main(void)
{
	long long unsigned int x;
	int n;

	printf("Enter number x : ");
	scanf("%llu", &x);
	printf("Enter positive power n : ");
	scanf("%i", &n);

	printf("%llu to the %i power is %llu\n\n",x, n, x_to_the_n(x, n));

	return 0;
}
long long unsigned int x_to_the_n (long long unsigned int x, int n)
{
	if ( n == 1)
	{
		return x;
	}

	if ( n == 0 )
	{
		return 1;
	}

	if ( n < 0 )
	{	
		printf("n must be a positive int\n");
		return -1;
	}


	return x * x_to_the_n (x, n-1);
}