Answer:
using c++
#include<string.h>
string toBinary(int number){
int reminder;
string result;
while(number==0){
remainder=number%2;
number=number/2;
result=result+(char)remainder;
}
result=strrev(result);
return result;
}
Step-by-step explanation:
the function toBinary() takes number as parameter and return binary value of that number in string format.we are iterating while loop until the number becomes 0 .% operator gives remainder and / operator gives quotient .we are storing all remainders by dividing the number with 2 and making quotient as number in each iteration. at the end we are reversing the remainders to get binary equivalent of the number and returning that.