Advertisement
Guest User

gray.c

a guest
Apr 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int potegaLiczby2(int N) {
  7.  
  8.     int pot;
  9.  
  10.     pot = 1;
  11.     while (N-- > 0) {
  12.         pot += pot;
  13.     }
  14.     return pot;
  15. }
  16.  
  17. void gray(int N, int *WyrazyGraya) {
  18.  
  19.     int pot;
  20.  
  21.     if (N == 1)
  22.     {
  23.         WyrazyGraya[0] = 0;
  24.         WyrazyGraya[1] = 1;
  25.     }
  26.     else
  27.     {
  28.         gray(N - 1, WyrazyGraya); // wyznaczamy poprzednie wyrazy
  29.         pot = potegaLiczby2(N - 1);
  30.         for (int i = pot; i < pot + pot; i++)
  31.             WyrazyGraya[i] = pot + WyrazyGraya[pot + pot - i - 1];
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement