Sunday 6 January 2019

Filled Under:

Checking if given number is binary number or not in c[c programming examples with output]

C programming examples with output

Checking if given number is binary number or not
Program

#include<stdo.h>
#include<conio.h>
main()
{
     int r,c;
     long n,t;
     clrscr();
     printf("Enter any number : ");
     scanf("%ld",&n);
     t=n;
     c=r=0;
     while(n>0)
     {
         if(n%10==0 || n%10==1)
         c++;
         r++;
         n=n/10;
     }
        if(c==r)
            printf("\n%ld is a binary number",t);
       else
            printf("\n%ld is not a binary number",t);
       getch();
}

Output:
Enter any number:12345
12345 is not a binary number
Enter any number:10000001
10000001 is a binary number

0 komentar:

Post a Comment