Assuming n is a decimal number.
Divide n by 2 repeatedly, and summing the remainders will give the number of one's in binary representation.
pseudocode of algorithm:
Enter value of n:
sum=0;
while n>0 {
sum=mod(n,2);
n=n/2 [integer division]
}
Display n, sum