Advertisement
rajeevs1992

bit array

Dec 25th, 2011
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include<stdio.h>
  2. #define SIZE(n) (n+8-(n%8))/8
  3. main()
  4. {
  5.     int upper,temp,i;
  6.     printf("Enter the largest number in list ");
  7.     scanf("%d",&upper);
  8.     upper+=1;
  9.     unsigned char list[SIZE(upper)];
  10.     for(temp=0;temp<SIZE(upper);temp++)
  11.         list[temp]=0;
  12.     printf("\nEnter list ");
  13.     scanf("%d",&temp);
  14.     while(temp<upper)
  15.     {
  16.         list[temp/8]=list[temp/8]|(1<<temp%8);
  17.         scanf("%d",&temp);
  18.     }
  19.     for(temp=0;temp<SIZE(upper);temp++)
  20.         for(i=0;i<8;i++)
  21.             if((list[temp]&(1<<i))!=0)
  22.                 printf("%d\t",temp*8+i);
  23.     printf("\n");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement