Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6.  
  7. int main (int argc, char ** argv) {
  8.     if (argc != 2 )
  9.         {
  10.         printf("Blad, wprowadzono nieprawidlowe argumenty \n");
  11.         return 1;
  12.         }
  13.  
  14.          int n = atoi(argv[1]);
  15.  
  16.    
  17.    
  18.     for (int i = 0; i < n; i ++){
  19.        
  20.         char* slowo = malloc(sizeof (*slowo));
  21.         *slowo = '\0';
  22.        
  23.         for (int j = i; j>0; j = j/2) {
  24.             if (j%2==0)
  25.             {strcat (slowo, "0");}
  26.             else
  27.             {strcat (slowo, "1"); }
  28.         }
  29.        
  30.         int l = strlen(slowo);
  31.        
  32.        
  33.         for(l; l>0; l--)
  34.         printf("%c", slowo[l]);
  35.         printf("0\n");
  36.            
  37.     }
  38.    
  39.    
  40.    
  41.    
  42.    
  43.    
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement