Program for Decimal number to Octal Conversion : Number System

February 6, 2025 No Comments » Hits : 249





Program to Convert Decimal number into Octal : Number System : Download


Logic of This Program :

  1. Accept Number from User
  2. As we are dividing number by 8 , we have only remainders 0,1,2,3,4,5,6,7 etc
  3. Take an array of remainder i. rem[20];
  4. Let ,Initial elements in rem[] be Zero
  5. In each iteration Store Remainder in the Array & Divide original number by 2
  6. Also Count the number of remainders stored
  7. To Convert into Binary Just Reverse Remainder array

Program :

#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 :

Enter the decimal number : 20
Octal number : 24

Download Code

Incoming search terms: