C++ Program:

- To check number is in binary or not

Example:

User Input: 11111

Output: Number is in binary form

#include <iostream>
using namespace std;

int binary(long long num) {
  while(num!=0){
    if(num%10==0 || num%10==1)
      num/=10;
    else return 0;
  }
  return 1;
}

int main() {
  long long num;
  cout<<"Enter Your number : ";
  cin>>num;
  if(binary(num))cout<<"Number is in binary form";
  else cout<<"Number is not in binary form";
  return 0;
}

Output:

  Enter Your number : 1101
  Number is in binary form
Program
number

Binary Numbers : Numbers with only 0 & 1 combination

Examples like: 101, 111, 10, 11111

Main Logic :

int binary(int num) {
  while(num!=0){
    if(num%10==0 || num%10==1)
      num/=10;
    else return 0;
  }
  return 1;
}

Divide the number by 10 while your number becomes 0[ZERO] &
In-between check, is there any remainder other than 0 & 1

Concept

Coming Soon !

Quick
Tutorial

Quote

The best preparation for good work tomorrow is to do good work today.