Attachment '8.3.c'

Download

   1 #include <stdio.h>
   2 int main( int argc, char **argv ) {
   3   int n, n1, two31, i, powerof2; 
   4 
   5   printf( "sizeof(int) = %d\n", sizeof(n)*8 );
   6   printf( "Enter n: ", n );
   7   scanf( "%d", &n );
   8 
   9   two31 = 1;
  10   i = 0;
  11   n1 = n / 2;
  12   while( (i < 30) && (n1 > 0)) {
  13       two31 = two31 * 2;
  14       i = i + 1;
  15       n1 = n1 / 2;
  16   }
  17 
  18   powerof2 = two31;
  19   while( powerof2 > 0 ) {
  20     printf( "%d", (n/powerof2)%2 );
  21     powerof2 = powerof2 / 2;
  22   }
  23 
  24   printf( "\n" );
  25       
  26   return 0;
  27 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.