Professional Documents
Culture Documents
com/c-programs/)
Table of Content
C Program to Convert Decimal number into Binary Number
(http://www.c4learn.com/c-programs/program-to-convert-decimal-number-into.html)
C Program to Convert Decimal number to Octal Number
C Program to Convert Decimal Number to Hexadecimal Number
(http://www.c4learn.com/c-programs/program-for-decimal-to-hexadecimal.html)
C Program to Convert Binary to Decimal number
(http://www.c4learn.com/c-programs/program-to-convert-binary-to-decimal.html)
C Program to Convert Decimal to Binary using Bitwise AND operator
(http://www.c4learn.com/c-programs/decimal-to-binary-using-bitwise-and.html)
(http://pics.c4learn.com/2013/03/C-Program-Decimal-to-Octal-Number-Conversion.gif)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void dec_oct(long int num)
// Function Definition
{
long int rem[50],i=0,length=0;
while(num>0)
{
rem[i]=num%8;
num=num/8;
i++;
length++;
}
printf("nOctal number : ");
for(i=length-1;i>=0;i--)
printf("%ld",rem[i]);
}
//================================================
void main()
{
long int num;
clrscr();
printf("Enter the decimal number : ");
scanf("%ld",&num);
dec_oct(num);
// Calling function
getch();
}
Output :
Explanation of C Program :
We are dividing the number by 8 and storing the reminder in the rem[] array.
while(num>0)
{
rem[i]=num%8;
num=num/8;
i++;
length++;
}
num = num / 8;
while(num>0)
{
--- Logic of
---
the Code
Now we are printing the reminders stored in an array in reverse order so that equivalent
octal number gets printed.
Download Program :
[box]Download Code (http://www.box.net/shared/oo3f1vilni)[/box]
Official HP Online
Store
Buy HP Original Toner
Cartridges. Free Same Day
Delivery. Pay COD.
0 Comments
Like Page
Get in Touch!
Recent Programs
C Program to read the content of file using fgets (http://www.c4learn.com/c-programs/readcontent-file-using-fgets.html)
C Program to perform arithmetic operations on float
(http://www.c4learn.com/c-programs/perform-arithmetic-operations-on-float.html)
C Program to perform arithmetic operations on integer
(http://www.c4learn.com/c-programs/perform-arithmetic-operations-integers.html)
C Program to count trailing zeros using bitwise operator
(http://www.c4learn.com/c-programs/count-trailing-zeros-using-bitwise-operator.html)
C Program to convert number to binary using bitwise operators
(http://www.c4learn.com/c-programs/convert-number-to-binary-using-bitwise-operators.html)