//binary to octal conversion
#include<stdio.h>
#include<math.h>
int main()
{
int binary,i=0,rem,c,count=0,x=0;
printf("enter a binary number for conversion to decimal\n");
scanf("%d",&binary);
while(count<=3);
{
rem=binary%10;
c=pow(2,i);
x+=rem*c;
i++;
count++;
}
printf("the converted binary number to octal is: %d",x);
getch();
return 0;
}
Mohammad Shaharyar Siddiqui
Programmer, Programming . . .
PrasannaKumar Muralidharan
Kernel developer @ Witworks
Use debugger to see what values are assigned to variables in every step. This will help you in fixing issues easily. Also it is better to have mental model of your code.
Try with "rem = binary % 2" instead of "rem = binary % 10". Just looked at your code, did not test the line, hope it works.