shipu_a

Write a Program Decimal to Binary & count 1.

Jan 29th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include<stdio.h>
  2.       int main()
  3.       {
  4.       int a, n, c[ 100 ], i, j,d ;
  5.       while((scanf("%d",&n))==1)
  6.       {
  7.       for(i=0 ; n>0 ; i++)
  8.       {
  9.       c[i]=n%2;
  10.       n=n / 2;
  11.       }
  12.       i=i-1;
  13.       d=0;
  14.       for(j=i ; j>=0 ; j--){
  15.       printf ("%d",c [j]);
  16.       if(c[j]==1)
  17.       d++;
  18.       }
  19.       printf("\n%d\n",d);
  20.       }
  21.       return 0;
  22.       }
Advertisement
Add Comment
Please, Sign In to add comment