Code.GeekInterview.com
  I am new, Sign me up!
 
Code Samples C
 

Count Numbers in Binary Number


Code ResourceAuthor: kaivalya1989  

Difficulty Level: Intermediate

Published: 15th Jul 2008   Read: 4851 times  

Filed in: C
Add Comment


 


this code is used to count the number of 0's and 1's in a binary number.

 


Sample Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. int n,x,a,b,s;
  6.  clrscr();
  7.  a=0;b=0;
  8.  printf("enter the binary no:");
  9.  scanf("%d",&n);
  10.  s=n;
  11.  while(n>0)
  12.   {
  13.    x=n%10;
  14.    n=n/10;
  15.    if(x==0)
  16.    a++;
  17.    else if(x==1)
  18.     b++;
  19.     }
  20.      printf("
  21. the number is:%d",s);
  22.      printf("
  23. the ones are:%d",b);
  24.      printf("
  25. the zeros are:%d",a);
  26.     getch();
  27.   }
Copyright GeekInterview.com


Next Article: Swaping two variables without using 3rd variable


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Comment


Members Please Login

Name:  Email: (Optional. Used for Notification)

Title:
 
Comment:
Validation Code: <=>  (Enter this code in text box)





Popular Coders

# Coder NameHits
1. kaivalya198914897
2. chandrikakr4781
3. meefriend4ever3547
4. sripri2893
5. deepu082813
6. Jimmy Zorald2564
7. Rajani1630
8. norman1442
9. reliable1097

Active Coders

# Coder NameCodes
1. kaivalya19894
2. sripri1
3. Jimmy Zorald1
4. norman1
5. Rajani1
6. meefriend4ever1
7. chandrikakr1
8. reliable1
9. deepu081

Refined Tags

 

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape