demical into binary number algorithm steps
Answers
Answered by
0
Answer:
- Decimal to Binary Conversion Algorithm
- Step 1: Divide the number by 2 through % (modulus operator) and store the remainder in array.
- Step 2: Divide the number by 2 through / (division operator)
- Step 3: Repeat the step 2 until number is greater than 0.
Answered by
2
Answer:
Decimal into binary no.
Explanation:
Step 1: Divide the number by 2 through % (modulus operator) and store the remainder in array
Step 2: Divide the number by 2 through / (division operator)
Step 3: Repeat the step 2 until number is greater than 0
Let's see the c example to convert decimal to binary.
#include<stdio.h>
#include<stdlib.h>
int main(){
int a[10],n,i;
system ("cls");
printf("Enter the number to convert: ");
scanf("%d",&n);
for(i=0;n>0;i++)
{
a[i]=n%2;
n=n/2;
}
printf("\nBinary of Given Number is=");
for(i=i-1;i>=0;i--)
{
printf("%d",a[i]);
}
return 0;
}
Output:
Enter the number to convert: 5
Binary of Given Number is=101
Similar questions