Programming In C
Improve your Programming Skills with almost every C Program.
Home
Blog Posts
Life Style
Relationship
Make Money
Follow Us
Facebook
Twitter
About Us
Who We Are?
Contact Us
Wednesday, November 2, 2011
Decimal to Octal
Q.
Write a program in C to convert a decimal number to its octal equivalent.
Ans.
Coding 4 decimal to octal
#include
<
stdio.h
>
#include
<
conio.h
>
void
convert(
int
num,
int
rem);
int
main()
{
int
n,m;
printf(
"Enter number to change in octal: "
);
scanf(
"%d"
,
&
n);
convert(n,m);
return
0
;
}
void
convert(
int
num,
int
rem)
{
if
(rem==0)
return
;
rem=num%8;
num=num/8;
convert(num,rem);
if
(rem!=0)
printf(
"%d"
,rem);
}
/******************
Output************
Enter number to change in octal :
786
1422
Hence, (786)
10
=(1422)
8
**********************
************/
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment