C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting
C > Beginners Lab Assignments sample source codes
Program to find the binary number has how many ones and zeros
Program to find the binary number has how many ones and zeros #include<stdio.h> #include<conio.h> void main() { int n,x,a,b,s; clrscr(); a=0;b=0; printf("enter the binary no:"); scanf("%d",&n); s=n; while(n>0) { x=n%10; n=n/10; if(x==0) a++; else if(x==1) b++; } printf(" the number is:%d",s); printf(" the ones are:%d",b); printf(" the zeros are:%d",a); getch(); }
Privacy Policy
|
Link to Us
|
Links