L-4 MCS 260 Mon 27 Aug 2001

Below are listings for programs we discussed in class.
/* L-4 MCS 260 Mon 27 Aug 2001 : binary decomposition of number */

#include <stdio.h>

int main(void)
{
   int n;

   printf("Give positive integer : ");
   scanf("%d",&n);

   while (n > 0)
   {
      printf("%d",n%2);
      n = n/2;
   }
   printf("\n");

   return 0;
}
The second program makes the conversion from decimal to hexadecimal notation.
/* L-4 MCS 260 Mon 27 Aug 2001 : number in hexadecimal format */

#include <stdio.h>

int main(void)
{
   int n;

   printf("Give positive integer : ");
   scanf("%d",&n);

   printf("  %d = %x in hexadecimal format\n", n, n);

   return 0;
}