-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoct bin.cpp
More file actions
52 lines (46 loc) · 720 Bytes
/
Copy pathoct bin.cpp
File metadata and controls
52 lines (46 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
long int rem[10],len=0,decimal=0,i=0,octal,check,oct=0;
printf("Enter the octal number: ");
scanf("%ld",&octal);
check=octal;
while(check!=0){
oct=check%10;
if(oct>7)
{
printf("%d is not octal number",oct);
return 0;
}
else
{
check=check/10;
i++;
}
}
i=0;
oct=0;
while(octal!=0){
oct=octal % 10;
decimal = decimal + oct * pow(8,i);
i++;
octal = octal/10;
}
i=0;
do
{
rem[i]=decimal%2;
decimal=decimal/2;
i++;
len++;
}
while(decimal!=0);
printf("binary number is : ");
for(i=len-1;i>=0;i--)
{
printf("%ld",rem[i]);
}
return 0;
}