Mega Code Archive

 
Categories / C / Beginners
 

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(); }