Guest User

Rozpacz 3

a guest
Dec 29th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. /* rozpacz3.c */
  2. #include <stdio.h>
  3.  
  4.  
  5. double intpower(double x, int n) {
  6.     /* nie obsluguje przypadku n=0 */
  7.     double wynik;
  8.     if (n == 1) return x;
  9.    
  10.     wynik = intpower(x,n/2);
  11.     if (n%2 == 0)
  12.         return wynik*wynik;
  13.     else
  14.         return wynik*wynik*x;
  15. }
  16.  
  17.  
  18.     /* --------------------------------------- */
  19.     /*         Szacowana liczba mnozen         */
  20.     /* --------------------------------------- */
  21.     /* Wyznaczamy rekurencyjna funkcje kosztu  */
  22.     /*            { T(1) = O(1)                */
  23.     /*     T(n) = {                      .     */
  24.     /*            { T(n) = T(n/2) + O(1)       */
  25.     /* Z twierdzenia o rekurencji uniwersalnej */
  26.     /* natychmiast otrzymujemy                 */
  27.     /*     T(n) = Theta(lgn).                  */
  28.     /* --------------------------------------- */
  29.  
  30.    
  31. int main(void) {
  32.     int i;
  33.     for (i=1; i<15; i++)
  34.         printf("%d^%d = %g\n", i,i, intpower(i,i));
  35.        
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment